Rename the suffix _get_at to the _safe_get suffix
(Better & clearer naming of the function)
This commit is contained in:
1 parent
e650addfe4
commit
51d4e930f5
9 files changed
+52
-27
No files matched your search
@@ -1727,7 +1727,7 @@ Return a constant pointer to the element 'i' of the array.
|
||||
The returned pointer cannot be NULL.
|
||||
This pointer remains valid until the array is modified by another method.
|
||||
|
||||
##### type *name\_get\_at(name\_t array, size\_t i)
|
||||
##### type *name\_safe\_get(name\_t array, size\_t i)
|
||||
|
||||
Return a pointer to the element 'i' of array 'array',
|
||||
by increasing the size of the array if needed (creating new elements with INIT).
|
||||
@@ -2442,7 +2442,7 @@ Return a pointer to the value associated to the key 'key' in dictionary
|
||||
'dict' or NULL if the key is not found.
|
||||
This pointer remains valid until the array is modified by another method.
|
||||
|
||||
##### value\_type *name\_get\_at(name\_t dict, const key\_type key)
|
||||
##### value\_type *name\_safe\_get(name\_t dict, const key\_type key)
|
||||
|
||||
Return a pointer to the value associated to the key 'key' in dictionary
|
||||
'dict' or create a new entry for the key 'key',
|
||||
@@ -3367,7 +3367,7 @@ or NULL if there is no element in the B+Tree.
|
||||
Return a pointer to the value of the tree 'tree' that is associated to 'data',
|
||||
or NULL if there is no match.
|
||||
|
||||
##### value\_type * name\_get\_at(name\_t tree, const key\_type data)
|
||||
##### value\_type * name\_safe\_get(name\_t tree, const key\_type data)
|
||||
|
||||
Return a pointer to the value of the tree 'tree' that is associated to 'data'.
|
||||
If the key doesn't exist yet in the tree, a new entry is created with 'key'
|
||||
@@ -4818,7 +4818,7 @@ If it exists, it sets '*value' to it and returns true.
|
||||
Otherwise it returns false.
|
||||
This method is only defined if the base container exports the GET\_KEY operator.
|
||||
|
||||
##### void name\_get\_at\_copy(value\_t *value, name\_t concurrent, key\_t key)
|
||||
##### void name\_safe\_get\_copy(value\_t *value, name\_t concurrent, key\_t key)
|
||||
|
||||
Read the value associated to the key 'key'.
|
||||
If it exists, it sets '*value' to it.
|
||||
|
||||
+1
-1
@@ -69,4 +69,4 @@ V0.5.*: * M_INVERT is renamed into M_REVERSE to be more coherent with the REVERS
|
||||
==> Encapsulate the argument between () to force use of INIT_WITH.
|
||||
* Remove of UPDATE operator. Use of SET for RBTREE or ADD for DICT instead.
|
||||
* Make the _clean suffix for reseting the container to empty deprecated. Use new _reset suffix instead.
|
||||
|
||||
* Make the _get_at suffix for always getting a value deprecated. Use new _safe_get suffix instead.
|
||||
@@ -113,7 +113,7 @@
|
||||
,VALUE_OPLIST(oplist) \
|
||||
,M_IF_METHOD(SET, oplist)(SET_KEY(M_C(name, _set_at)) ,) \
|
||||
,GET_KEY(M_C(name, _get)) \
|
||||
,M_IF_METHOD(INIT, oplist)(GET_SET_KEY(M_C(name, _get_at)) ,) \
|
||||
,M_IF_METHOD(INIT, oplist)(GET_SET_KEY(M_C(name, _safe_get)) ,) \
|
||||
,M_IF_AT_LEAST_METHOD(SET,INIT_MOVE,oplist)(ERASE_KEY(M_C(name, _erase)),) \
|
||||
,GET_SIZE(M_C(name, _size)) \
|
||||
,M_IF_METHOD(INIT_SET, oplist)(PUSH(M_C(name,_push_back)) ,) \
|
||||
@@ -207,12 +207,12 @@
|
||||
M_ARRA4_CONTRACT(v); \
|
||||
} \
|
||||
\
|
||||
static inline void M_ATTR_DEPRECATED \
|
||||
static inline void M_ATTR_DEPRECATED \
|
||||
M_C(name, _clean)(array_t v) \
|
||||
{ \
|
||||
M_C(name, _reset)(v); \
|
||||
M_C(name, _reset)(v); \
|
||||
} \
|
||||
\
|
||||
\
|
||||
static inline void \
|
||||
M_C(name, _clear)(array_t v) \
|
||||
{ \
|
||||
@@ -453,7 +453,7 @@
|
||||
\
|
||||
M_IF_METHOD(INIT, oplist)( \
|
||||
static inline type * \
|
||||
M_C(name, _get_at)(array_t v, size_t idx) \
|
||||
M_C(name, _safe_get)(array_t v, size_t idx) \
|
||||
{ \
|
||||
M_ARRA4_CONTRACT(v); \
|
||||
const size_t size = idx + 1; \
|
||||
@@ -483,6 +483,11 @@
|
||||
M_ARRA4_CONTRACT(v); \
|
||||
return &v->ptr[idx]; \
|
||||
} \
|
||||
static inline M_ATTR_DEPRECATED type * \
|
||||
M_C(name, _get_at)(array_t v, size_t idx) \
|
||||
{ \
|
||||
return M_C(name, _safe_get)(v, idx); \
|
||||
} \
|
||||
, /* No INIT */) \
|
||||
\
|
||||
M_IF_AT_LEAST_METHOD(SET, INIT_MOVE, oplist)( \
|
||||
|
||||
+7
-2
@@ -234,7 +234,7 @@
|
||||
VALUE_TYPE(M_C(name, _value_ct)), \
|
||||
SET_KEY(M_C(name, _set_at)), \
|
||||
GET_KEY(M_C(name, _get)), \
|
||||
GET_SET_KEY(M_C(name, _get_at)) \
|
||||
GET_SET_KEY(M_C(name, _safe_get)) \
|
||||
ERASE_KEY(M_C(name, _erase)), \
|
||||
KEY_OPLIST(key_oplist), \
|
||||
VALUE_OPLIST(value_oplist), \
|
||||
@@ -766,7 +766,7 @@
|
||||
} \
|
||||
} \
|
||||
\
|
||||
static inline value_t *M_C(name, _get_at)(tree_t b, key_t const key) \
|
||||
static inline value_t *M_C(name, _safe_get)(tree_t b, key_t const key) \
|
||||
{ \
|
||||
M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \
|
||||
/* Not optimized implementation */ \
|
||||
@@ -782,6 +782,11 @@
|
||||
ret = M_C(name, _get)(b, key); \
|
||||
} \
|
||||
return ret; \
|
||||
} \
|
||||
static inline M_ATTR_DEPRECATED value_t * \
|
||||
M_C(name, _get_at)(tree_t b, key_t const key) \
|
||||
{ \
|
||||
return M_C(name, _safe_get)(b, key); \
|
||||
} \
|
||||
\
|
||||
static inline int \
|
||||
|
||||
+6
-1
@@ -484,7 +484,7 @@
|
||||
\
|
||||
M_IF_METHOD(GET_SET_KEY, oplist)( \
|
||||
static inline void \
|
||||
M_C(name, _get_at_copy)(M_GET_VALUE_TYPE oplist *out_data, concurrent_t out, M_GET_KEY_TYPE oplist const key) \
|
||||
M_C(name, _safe_get_copy)(M_GET_VALUE_TYPE oplist *out_data, concurrent_t out, M_GET_KEY_TYPE oplist const key) \
|
||||
{ \
|
||||
M_C0NCURRENT_CONTRACT(out); \
|
||||
M_ASSERT (out_data != NULL); \
|
||||
@@ -494,6 +494,11 @@
|
||||
M_CALL_SET(M_GET_VALUE_OPLIST oplist, *out_data, *p); \
|
||||
M_C(name, _write_unlock)(out); \
|
||||
} \
|
||||
static inline M_ATTR_DEPRECATED void \
|
||||
M_C(name, _get_at_copy)(M_GET_VALUE_TYPE oplist *out_data, concurrent_t out, M_GET_KEY_TYPE oplist const key) \
|
||||
{ \
|
||||
M_C(name, _safe_get_copy)(out_data, out, key); \
|
||||
} \
|
||||
,) \
|
||||
\
|
||||
M_IF_METHOD(ERASE_KEY, oplist)( \
|
||||
|
||||
@@ -565,7 +565,7 @@
|
||||
} \
|
||||
\
|
||||
static inline value_type * \
|
||||
M_C(name, _get_at)(dict_t map, key_type const key) \
|
||||
M_C(name, _safe_get)(dict_t map, key_type const key) \
|
||||
{ \
|
||||
M_D1CT_CONTRACT(name, map); \
|
||||
\
|
||||
@@ -595,6 +595,11 @@
|
||||
} \
|
||||
M_D1CT_CONTRACT(name, map); \
|
||||
return &(*ref)->M_IF(isSet)(key, value); \
|
||||
} \
|
||||
static inline M_ATTR_DEPRECATED value_type * \
|
||||
M_C(name, _get_at)(dict_t map, key_type const key) \
|
||||
{ \
|
||||
return M_C(name, _safe_get)(map, key); \
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
@@ -1074,7 +1079,7 @@
|
||||
,VALUE_TYPE(M_C(name, _value_ct)) \
|
||||
,SET_KEY(M_C(name, _set_at)) \
|
||||
,GET_KEY(M_C(name, _get)) \
|
||||
,GET_SET_KEY(M_C(name, _get_at)) \
|
||||
,GET_SET_KEY(M_C(name, _safe_get)) \
|
||||
,ERASE_KEY(M_C(name, _erase)) \
|
||||
,KEY_OPLIST(key_oplist) \
|
||||
,VALUE_OPLIST(value_oplist) \
|
||||
@@ -1124,7 +1129,7 @@
|
||||
KEY_TYPE(M_C(name, _key_ct)), \
|
||||
VALUE_TYPE(M_C(name, _key_ct)), \
|
||||
GET_KEY(M_C(name, _get)), \
|
||||
GET_SET_KEY(M_C(name, _get_at)), \
|
||||
GET_SET_KEY(M_C(name, _safe_get)), \
|
||||
ERASE_KEY(M_C(name, _erase)), \
|
||||
KEY_OPLIST(oplist), \
|
||||
VALUE_OPLIST(oplist), \
|
||||
@@ -1522,7 +1527,7 @@ enum m_d1ct_oa_element_e {
|
||||
} \
|
||||
\
|
||||
static inline value_type * \
|
||||
M_C(name,_get_at)(dict_t dict, key_type const key) \
|
||||
M_C(name,_safe_get)(dict_t dict, key_type const key) \
|
||||
{ \
|
||||
M_D1CT_OA_CONTRACT(dict); \
|
||||
/* NOTE: key can not be the representation of empty or deleted */ \
|
||||
@@ -1573,6 +1578,11 @@ enum m_d1ct_oa_element_e {
|
||||
} \
|
||||
M_D1CT_OA_CONTRACT(dict); \
|
||||
return &data[p].M_IF(isSet)(key, value); \
|
||||
} \
|
||||
static inline M_ATTR_DEPRECATED value_type * \
|
||||
M_C(name,_get_at)(dict_t dict, key_type const key) \
|
||||
{ \
|
||||
return M_C(name,_safe_get)(dict, key); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
|
||||
+1
-1
@@ -309,7 +309,7 @@ static void test_d(void)
|
||||
for(int i = 9; i < 19; i++)
|
||||
assert (*array_uint_get (a1, (size_t) i) == 18U -(unsigned int) i);
|
||||
|
||||
*array_uint_get_at(a1, 100) = 100;
|
||||
*array_uint_safe_get(a1, 100) = 100;
|
||||
assert (*array_uint_back(a1) == 100);
|
||||
assert (array_uint_size(a1) == 101);
|
||||
array_uint_pop_back (NULL, a1);
|
||||
|
||||
@@ -155,10 +155,10 @@ static void test1(void)
|
||||
assert (btree_size(b) == 0);
|
||||
assert (btree_empty_p(b));
|
||||
|
||||
int *p = btree_get_at(b, 1000);
|
||||
int *p = btree_safe_get(b, 1000);
|
||||
assert(p != NULL && *p == 0);
|
||||
*p = 23;
|
||||
p = btree_get_at(b, 1000);
|
||||
p = btree_safe_get(b, 1000);
|
||||
assert(p != NULL && *p == 23);
|
||||
|
||||
btree_clear(b);
|
||||
|
||||
+7
-7
@@ -154,7 +154,7 @@ static void test_set(void)
|
||||
string_t *p = dict_setstr_get(set, str);
|
||||
assert (p != NULL);
|
||||
assert(string_equal_p (*p, str));
|
||||
p = dict_setstr_get_at(set, str);
|
||||
p = dict_setstr_safe_get(set, str);
|
||||
assert (p != NULL);
|
||||
assert(string_equal_p (*p, str));
|
||||
}
|
||||
@@ -179,7 +179,7 @@ static void test_init(void)
|
||||
string_t *p = dict_str_get (d1, str1);
|
||||
assert (p != NULL);
|
||||
assert (string_equal_p(*p, str2));
|
||||
p = dict_str_get_at (d1, str1);
|
||||
p = dict_str_safe_get (d1, str1);
|
||||
assert (p != NULL);
|
||||
assert (string_equal_p(*p, str2));
|
||||
}
|
||||
@@ -229,7 +229,7 @@ static void test_init(void)
|
||||
assert (dict_str_size (d1) == 100);
|
||||
for(int i = 100; i < 200; i++) {
|
||||
string_printf(str1, "%d", 2*i);
|
||||
string_printf(*dict_str_get_at (d1, str1), "%d", 2*i+1);
|
||||
string_printf(*dict_str_safe_get (d1, str1), "%d", 2*i+1);
|
||||
}
|
||||
assert (dict_str_size (d1) == 200);
|
||||
for(int i = 100; i < 200; i++) {
|
||||
@@ -238,7 +238,7 @@ static void test_init(void)
|
||||
string_t *p = dict_str_get (d1, str1);
|
||||
assert (p != NULL);
|
||||
assert (string_equal_p(*p, str2));
|
||||
p = dict_str_get_at (d1, str1);
|
||||
p = dict_str_safe_get (d1, str1);
|
||||
assert (p != NULL);
|
||||
assert (string_equal_p(*p, str2));
|
||||
}
|
||||
@@ -356,7 +356,7 @@ static void test_oa(void)
|
||||
assert(dict_oa_int_size(d) == 50);
|
||||
|
||||
for(int i = 1 ; i < 150; i+= 3)
|
||||
*dict_oa_int_get_at(d, i) = i*i;
|
||||
*dict_oa_int_safe_get(d, i) = i*i;
|
||||
assert(dict_oa_int_size(d) == 100);
|
||||
for(int i = 0 ; i < 150; i++) {
|
||||
int *p = dict_oa_int_get(d, i);
|
||||
@@ -506,7 +506,7 @@ test_oa_str1(void)
|
||||
dict_oa_str_set_at(dict, BOUNDED_STRING_CTE(symbol, "y"), 2);
|
||||
dict_oa_str_set_at(dict, BOUNDED_STRING_CTE(symbol, "z"), 3);
|
||||
|
||||
p = dict_oa_str_get_at(dict, BOUNDED_STRING_CTE(symbol, "x"));
|
||||
p = dict_oa_str_safe_get(dict, BOUNDED_STRING_CTE(symbol, "x"));
|
||||
assert(p != NULL);
|
||||
assert(*p == 1);
|
||||
|
||||
@@ -526,7 +526,7 @@ test_oa_str2(void)
|
||||
dict_oa_bstr_set_at(dict, STRING_CTE("y"), 2);
|
||||
dict_oa_bstr_set_at(dict, STRING_CTE("z"), 3);
|
||||
|
||||
p = dict_oa_bstr_get_at(dict, STRING_CTE("x"));
|
||||
p = dict_oa_bstr_safe_get(dict, STRING_CTE("x"));
|
||||
assert(p != NULL);
|
||||
assert(*p == 1);
|
||||
|
||||
|
||||
Reference in new issue
Block a user