From a9fc7e15f8db9710f92670e2be9e09a2ff5135c8 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 30 Oct 2021 23:56:58 +0200 Subject: [PATCH] Rename GET_SET_KEY operator in SAFE_GET_KEY operator --- README.md | 2 +- doc/API.txt | 1 + m-array.h | 2 +- m-bptree.h | 2 +- m-concurrent.h | 4 ++-- m-core.h | 6 +++--- m-dict.h | 4 ++-- tests/check-generic.hpp | 4 ++-- 8 files changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index c20806f0..b792db3f 100644 --- a/README.md +++ b/README.md @@ -549,7 +549,7 @@ Other documented operators are: * DIV(obj1, obj2, obj3) : Set obj1 to the division of obj2 and obj3. Default is '/' C operator. * GET\_KEY (container, key) --> &value: Return a pointer to the value object within the container associated to the key 'key' or return NULL if no object is associated to this key. The pointer to the value object remains valid until any modification of the container. * SET\_KEY (container, key, value): Associate the key object 'key' to the value object 'value' in the given container. -* GET\_SET\_KEY (container, key) --> &value: return a pointer to the value object within the container associated to the key 'key' if it exists, or create a new entry in the container and associate it to the key 'key' with the default initialization before returning its pointer. The pointer to the object remains valid until any modification of the container. The returned pointer is therefore never NULL. +* SAFE\_GET\_KEY (container, key) --> &value: return a pointer to the value object within the container associated to the key 'key' if it exists, or create a new entry in the container and associate it to the key 'key' with the default initialization before returning its pointer. The pointer to the object remains valid until any modification of the container. The returned pointer is therefore never NULL. * ERASE\_KEY (container, key) --> bool: Erase the object associated to the key 'key' within the container. Return true if successful, false if the key is not found (nothing is done). * PUSH(obj, subobj) : Push 'subobj' (of type SUBTYPE() ) into the container 'obj'. How and where it is pushed is container dependent. * POP(&subobj, obj) : Pop an object from the container 'obj' and save it in the object '*subobj' (of type SUBTYPE()) if subobj is not NULL (giving back the ownership of the sub object to the caller). Which object is popped is container dependent. The container shall have at least one object. diff --git a/doc/API.txt b/doc/API.txt index e01eb7aa..26648bfd 100644 --- a/doc/API.txt +++ b/doc/API.txt @@ -71,4 +71,5 @@ V0.5.*: * M_INVERT is renamed into M_REVERSE to be more coherent with the REVERS * 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. * Rename CLEAN operator in RESET operator. + * Rename GET_SET_KEY operator in SAFE_GET_KEY operator. diff --git a/m-array.h b/m-array.h index e1819444..271c89a1 100644 --- a/m-array.h +++ b/m-array.h @@ -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, _safe_get)) ,) \ + ,M_IF_METHOD(INIT, oplist)(SAFE_GET_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)) ,) \ diff --git a/m-bptree.h b/m-bptree.h index 22e5afcc..912975a1 100644 --- a/m-bptree.h +++ b/m-bptree.h @@ -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, _safe_get)) \ + SAFE_GET_KEY(M_C(name, _safe_get)) \ ERASE_KEY(M_C(name, _erase)), \ KEY_OPLIST(key_oplist), \ VALUE_OPLIST(value_oplist), \ diff --git a/m-concurrent.h b/m-concurrent.h index d028d8af..a481d856 100644 --- a/m-concurrent.h +++ b/m-concurrent.h @@ -482,14 +482,14 @@ } \ ,) \ \ - M_IF_METHOD(GET_SET_KEY, oplist)( \ + M_IF_METHOD(SAFE_GET_KEY, oplist)( \ static inline void \ 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); \ M_C(name, _write_lock)(out); \ - M_GET_VALUE_TYPE oplist *p = M_CALL_GET_SET_KEY(oplist, out->data, key); \ + M_GET_VALUE_TYPE oplist *p = M_CALL_SAFE_GET_KEY(oplist, out->data, key); \ M_ASSERT (p != NULL); \ M_CALL_SET(M_GET_VALUE_OPLIST oplist, *out_data, *p); \ M_C(name, _write_unlock)(out); \ diff --git a/m-core.h b/m-core.h index ae811b37..b2455953 100644 --- a/m-core.h +++ b/m-core.h @@ -2757,7 +2757,7 @@ static inline size_t m_core_cstr_hash(const char str[]) #define M_VALUE_OPLIST_VALUE_OPLIST(a) ,a, #define M_GET_KEY_GET_KEY(a) ,a, #define M_SET_KEY_SET_KEY(a) ,a, -#define M_GET_SET_KEY_GET_SET_KEY(a) ,a, +#define M_SAFE_GET_KEY_SAFE_GET_KEY(a) ,a, #define M_ERASE_KEY_ERASE_KEY(a) ,a, #define M_GET_SIZE_GET_SIZE(a) ,a, #define M_PUSH_PUSH(a) ,a, @@ -2841,7 +2841,7 @@ static inline size_t m_core_cstr_hash(const char str[]) #define M_GET_VALUE_OPLIST(...) M_GET_METHOD(VALUE_OPLIST, M_NO_DEF_TYPE, __VA_ARGS__) #define M_GET_GET_KEY(...) M_GET_METHOD(GET_KEY, M_NO_DEFAULT, __VA_ARGS__) #define M_GET_SET_KEY(...) M_GET_METHOD(SET_KEY, M_NO_DEFAULT, __VA_ARGS__) -#define M_GET_GET_SET_KEY(...) M_GET_METHOD(GET_SET_KEY, M_NO_DEFAULT, __VA_ARGS__) +#define M_GET_SAFE_GET_KEY(...) M_GET_METHOD(SAFE_GET_KEY, M_NO_DEFAULT, __VA_ARGS__) #define M_GET_ERASE_KEY(...) M_GET_METHOD(ERASE_KEY, M_NO_DEFAULT, __VA_ARGS__) #define M_GET_GET_SIZE(...) M_GET_METHOD(GET_SIZE, M_NO_DEFAULT, __VA_ARGS__) #define M_GET_PUSH(...) M_GET_METHOD(PUSH, M_NO_DEFAULT, __VA_ARGS__) @@ -2911,7 +2911,7 @@ static inline size_t m_core_cstr_hash(const char str[]) #define M_CALL_RESET(oplist, ...) M_APPLY_API(M_GET_RESET oplist, oplist, __VA_ARGS__) #define M_CALL_GET_KEY(oplist, ...) M_APPLY_API(M_GET_GET_KEY oplist, oplist, __VA_ARGS__) #define M_CALL_SET_KEY(oplist, ...) M_APPLY_API(M_GET_SET_KEY oplist, oplist, __VA_ARGS__) -#define M_CALL_GET_SET_KEY(oplist, ...) M_APPLY_API(M_GET_GET_SET_KEY oplist, oplist, __VA_ARGS__) +#define M_CALL_SAFE_GET_KEY(oplist, ...) M_APPLY_API(M_GET_SAFE_GET_KEY oplist, oplist, __VA_ARGS__) #define M_CALL_ERASE_KEY(oplist, ...) M_APPLY_API(M_GET_ERASE_KEY oplist, oplist, __VA_ARGS__) #define M_CALL_GET_SIZE(oplist, ...) M_APPLY_API(M_GET_GET_SIZE oplist, oplist, __VA_ARGS__) #define M_CALL_PUSH(oplist, ...) M_APPLY_API(M_GET_PUSH oplist, oplist, __VA_ARGS__) diff --git a/m-dict.h b/m-dict.h index 8de661e6..8681c169 100644 --- a/m-dict.h +++ b/m-dict.h @@ -1079,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, _safe_get)) \ + ,SAFE_GET_KEY(M_C(name, _safe_get)) \ ,ERASE_KEY(M_C(name, _erase)) \ ,KEY_OPLIST(key_oplist) \ ,VALUE_OPLIST(value_oplist) \ @@ -1129,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, _safe_get)), \ + SAFE_GET_KEY(M_C(name, _safe_get)), \ ERASE_KEY(M_C(name, _erase)), \ KEY_OPLIST(oplist), \ VALUE_OPLIST(oplist), \ diff --git a/tests/check-generic.hpp b/tests/check-generic.hpp index 30bc03f6..8f2e78e4 100644 --- a/tests/check-generic.hpp +++ b/tests/check-generic.hpp @@ -226,11 +226,11 @@ void test(int select_test, int index, break; #endif -#if M_TEST_METHOD_P(GET_SET_KEY, CONT_OPL) +#if M_TEST_METHOD_P(SAFE_GET_KEY, CONT_OPL) case 14: // To rework for dict index = (1 + (c1.size() < 1000000)) * (index % ( c1.size() + 1) ); - M_CALL_SET(M_GET_OPLIST CONT_OPL, b0, *M_CALL_GET_SET_KEY(CONT_OPL, c0, index)); + M_CALL_SET(M_GET_OPLIST CONT_OPL, b0, *M_CALL_SAFE_GET_KEY(CONT_OPL, c0, index)); #ifndef HAVE_GET_KEY_THROUGH_FIND if ((size_t) index >= c1.size() ) { c1.resize(index+1);