From 1b4c6080873f3e432a0e590d54618d40dfb958d5 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Fri, 1 Jan 2021 23:22:36 +0100 Subject: [PATCH] Rename operator TEST_EMPTY into EMPTY_P to be compliant with iterator operator --- README.md | 15 ++++++++------- m-array.h | 2 +- m-bitset.h | 2 +- m-bptree.h | 2 +- m-buffer.h | 2 +- m-concurrent.h | 14 +++++++------- m-core.h | 6 +++--- m-deque.h | 2 +- m-dict.h | 4 ++-- m-i-list.h | 2 +- m-list.h | 2 +- m-prioqueue.h | 2 +- m-rbtree.h | 2 +- m-string.h | 2 +- m-variant.h | 2 +- 15 files changed, 31 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 715d7cbf..020bd45d 100644 --- a/README.md +++ b/README.md @@ -519,6 +519,8 @@ Other documented operators are: * INIT\_WITH(obj, ...): Initialize the object 'obj' with a variable set of arguments. Arguments can be of different types and is up to the method to decide how to initialize the object based on this set. This is used in the M\_LET macro to initialize objects with the given values. * SWAP(objd, objc): Swap the states of the object 'objc' and the object 'objd'. * CLEAN(obj): Empty the container from all its objects. Nearly like CLEAR except that the container 'obj' remains initialized (but empty). +* EMPTY\_P(obj) --> bool: Test if the object is empty (true) or not. +* GET\_SIZE (container) --> size\_t: Return the number of elements in the container. * HASH (obj) --> size_t: return a hash of the object (not a secure hash but one that is usable for a hash table). Default is performing a hash of the memory representation of the object. This default implementation is invalid if the object holds pointer to other objects. * EQUAL(obj1, obj2) --> bool: Compare the object for equality. return true if both objects are equal, false otherwise. Default is using the C comparison operator. The method may be called with OOR object for the Open Addressing dictionary (in which case it shall return false). * CMP(obj1, obj2) --> int: Provide a complete order the objects. return a negative integer if obj1 < obj2, 0 if obj1 = obj2, a positive integer otherwise. Default is C comparison operator. @@ -530,7 +532,6 @@ Other documented operators are: * SET\_KEY (container, key, object): Associate the key 'key' to the value object 'object' in the given container. * GET\_SET\_KEY (container, key) --> &obj: return a pointer to the value object within the container associated to the key 'key' or create a new object in the container, associate it to the key 'key' (with default initialization) and return 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. -* GET\_SIZE (container) --> size_t: Return the number of elements in the container. * PUSH(container, obj) : Push 'object' into 'container'. How and where it is pushed is container dependent. * POP(&obj, container) : Pop an object from 'container' and save it in the initialized object '*obj' if obj is not NULL (giving back the ownership to the caller). Which object is popped is container dependent. The container shall have at least one object. * PUSH_MOVE(container, &obj) : Push and move the object '*obj' into 'container'. How it is pushed is container dependent. '*obj' is cleared afterward and shall not be used anymore. @@ -4525,7 +4526,7 @@ This method is only defined if the base container exports the SWAP operator. ##### bool name\_empty\_p(const name\_t concurrent) Return true if the container is empty, false otherwise. -This method is only defined if the base container exports the TEST\_EMPTY operator. +This method is only defined if the base container exports the EMPTY\_P operator. ##### void name\_set\_at(name\_t concurrent, key\_t key, value\_t value) @@ -4561,9 +4562,9 @@ This method is only defined if the base container exports the PUSH operator. Pop data from the container and set it in '*data'. There shall be at least one data to pop. -Testing with TEST_EMPTY before calling this function is not enough +Testing with the operator EMPTY\_P before calling this function is not enough as there can be some concurrent scenario where another thread pop the last value. -It is highly recommending to use name\_pop\_blocking instead which is safer. +name\_pop\_blocking should be used instead. This method is only defined if the base container exports the POP operator. ##### void name\_push\_move(name\_t concurrent, subtype\_t data) @@ -4575,7 +4576,7 @@ This method is only defined if the base container exports the PUSH\_MOVE operato ##### void name\_pop\_move(subtype\_t *data, name\_t concurrent) Pop data from the container and initialize '*data' with it. -It is highly recommending to use name\_pop\_move\_blocking instead which is safer. +name\_pop\_move\_blocking should be used instead (See name\_pop for details). This method is only defined if the base container exports the POP\_MOVE operator. ##### void name\_get\_str(string\_t str, name\_t concurrent, bool append) @@ -4621,7 +4622,7 @@ If the container is not empty, it sets '*data' and return true. Otherwise if blocking is true, it waits for the data to be pushed. After the wait, it sets '*data' to it and returns true. Otherwise if blocking is false, it returns false. -This method is only defined if the base container exports the POP and TEST\_EMPTY operators. +This method is only defined if the base container exports the POP and EMPTY\_P operators. ##### bool name\_pop\_move\_blocking(type_t *data, name\_t concurrent, bool blocking) @@ -4630,7 +4631,7 @@ If the container is not empty, it initializes & sets '*data' and return true. Otherwise if blocking is true, it waits for the data to be pushed. After the wait, it initializes & sets '*data' to it and returns true. Otherwise if blocking is false, it returns false (*data remains uninitialized!). -This method is only defined if the base container exports the POP\_MOVE and TEST\_EMPTY operators. +This method is only defined if the base container exports the POP\_MOVE and EMPTY\_P operators. ##### size\_t name\_hash(name\_t concurrent) diff --git a/m-array.h b/m-array.h index 3a40472e..ad4f5569 100644 --- a/m-array.h +++ b/m-array.h @@ -88,7 +88,7 @@ ,SWAP(M_C(name, _swap)) \ ,TYPE(M_C(name,_ct)) \ ,SUBTYPE(M_C(name, _subtype_ct)) \ - ,TEST_EMPTY(M_C(name,_empty_p)) \ + ,EMPTY_P(M_C(name,_empty_p)) \ ,IT_TYPE(M_C(name,_it_ct)), \ ,IT_FIRST(M_C(name,_it)) \ ,IT_LAST(M_C(name,_it_last)) \ diff --git a/m-bitset.h b/m-bitset.h index 5a988e6e..fb724a22 100644 --- a/m-bitset.h +++ b/m-bitset.h @@ -776,7 +776,7 @@ bitset_clz(const bitset_t set) ,SWAP(bitset_swap) \ ,TYPE(bitset_t) \ ,SUBTYPE(bool) \ - ,TEST_EMPTY(bitset_empty_p), \ + ,EMPTY_P(bitset_empty_p), \ ,GET_SIZE(bitset_size) \ ,IT_TYPE(bitset_it_t) \ ,IT_FIRST(bitset_it) \ diff --git a/m-bptree.h b/m-bptree.h index 964a1e2e..47bbb4f0 100644 --- a/m-bptree.h +++ b/m-bptree.h @@ -232,7 +232,7 @@ SWAP(M_C(name, _swap)), \ TYPE(M_C(name,_ct)), \ SUBTYPE(M_C(name, _subtype_ct)), \ - TEST_EMPTY(M_C(name,_empty_p)), \ + EMPTY_P(M_C(name,_empty_p)), \ IT_TYPE(M_C(name, _it_ct)), \ IT_FIRST(M_C(name,_it)), \ IT_SET(M_C(name,_it_set)), \ diff --git a/m-buffer.h b/m-buffer.h index 1af1165d..45c2b3e6 100644 --- a/m-buffer.h +++ b/m-buffer.h @@ -1170,7 +1170,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ ,PUSH(M_C(name,_push)) \ ,POP(M_C(name,_pop)) \ ,OPLIST(oplist) \ - ,TEST_EMPTY(M_C(name, _empty_p)), \ + ,EMPTY_P(M_C(name, _empty_p)), \ ,GET_SIZE(M_C(name, _size)) \ ) diff --git a/m-concurrent.h b/m-concurrent.h index b5ca6afe..5c72d9c4 100644 --- a/m-concurrent.h +++ b/m-concurrent.h @@ -114,7 +114,7 @@ ,TYPE(M_C(name,_ct)) \ ,SUBTYPE(M_C(name, _subtype_ct)) \ ,OPLIST(oplist) \ - ,M_IF_METHOD(TEST_EMPTY, oplist)(TEST_EMPTY(M_C(name,_empty_p)),) \ + ,M_IF_METHOD(EMPTY_P, oplist)(EMPTY_P(M_C(name,_empty_p)),) \ ,M_IF_METHOD(GET_SIZE, oplist)(GET_SIZE(M_C(name,_size)),) \ ,M_IF_METHOD(CLEAN, oplist)(CLEAN(M_C(name,_clean)),) \ ,M_IF_METHOD(KEY_TYPE, oplist)(KEY_TYPE(M_GET_KEY_TYPE oplist),) \ @@ -432,13 +432,13 @@ } \ ,) \ \ - M_IF_METHOD(TEST_EMPTY, oplist)( \ + M_IF_METHOD(EMPTY_P, oplist)( \ static inline bool \ M_C(name, _empty_p)(concurrent_t const out) \ { \ CONCURRENTI_CONTRACT(out); \ M_C(name, _read_lock)(out); \ - bool b = M_CALL_TEST_EMPTY(oplist, out->data); \ + bool b = M_CALL_EMPTY_P(oplist, out->data); \ M_C(name, _read_unlock)(out); \ return b; \ } \ @@ -684,7 +684,7 @@ } \ ,) \ \ - M_IF_METHOD2(POP, TEST_EMPTY, oplist)( \ + M_IF_METHOD2(POP, EMPTY_P, oplist)( \ static inline bool \ M_C(name, _pop_blocking)(M_GET_SUBTYPE oplist *p, concurrent_t out, bool blocking) \ { \ @@ -693,7 +693,7 @@ bool ret = false; \ M_C(name, _write_lock)(out); \ while (true) { \ - if (!M_CALL_TEST_EMPTY(oplist, out->data)) { \ + if (!M_CALL_EMPTY_P(oplist, out->data)) { \ M_CALL_POP(oplist, p, out->data); \ ret = true; \ break; \ @@ -707,7 +707,7 @@ } \ ,) \ \ - M_IF_METHOD2(POP_MOVE, TEST_EMPTY, oplist)( \ + M_IF_METHOD2(POP_MOVE, EMPTY_P, oplist)( \ static inline bool \ M_C(name, _pop_move_blocking)(M_GET_SUBTYPE oplist *p, concurrent_t out, bool blocking) \ { \ @@ -716,7 +716,7 @@ bool ret = false; \ M_C(name, _write_lock)(out); \ while (true) { \ - if (!M_CALL_TEST_EMPTY(oplist, out->data)) { \ + if (!M_CALL_EMPTY_P(oplist, out->data)) { \ M_CALL_POP_MOVE(oplist, p, out->data); \ ret = true; \ break; \ diff --git a/m-core.h b/m-core.h index 9932b9e8..e2ecf4de 100644 --- a/m-core.h +++ b/m-core.h @@ -2355,7 +2355,7 @@ static inline size_t m_core_cstr_hash(const char str[]) #define M_IT_CREF_IT_CREF(a) ,a, #define M_IT_REMOVE_IT_REMOVE(a) ,a, #define M_IT_INSERT_IT_INSERT(a) ,a, -#define M_TEST_EMPTY_TEST_EMPTY(a) ,a, +#define M_EMPTY_P_EMPTY_P(a) ,a, #define M_ADD_ADD(a) ,a, #define M_SUB_SUB(a) ,a, #define M_MUL_MUL(a) ,a, @@ -2435,7 +2435,7 @@ static inline size_t m_core_cstr_hash(const char str[]) #define M_GET_IT_CREF(...) M_GET_METHOD(IT_CREF, M_NO_DEFAULT, __VA_ARGS__) #define M_GET_IT_REMOVE(...) M_GET_METHOD(IT_REMOVE, M_NO_DEFAULT, __VA_ARGS__) #define M_GET_IT_INSERT(...) M_GET_METHOD(IT_INSERT, M_NO_DEFAULT, __VA_ARGS__) -#define M_GET_TEST_EMPTY(...) M_GET_METHOD(TEST_EMPTY, M_NO_DEFAULT, __VA_ARGS__) +#define M_GET_EMPTY_P(...) M_GET_METHOD(EMPTY_P, M_NO_DEFAULT, __VA_ARGS__) #define M_GET_ADD(...) M_GET_METHOD(ADD, M_ADD_DEFAULT, __VA_ARGS__) #define M_GET_SUB(...) M_GET_METHOD(SUB, M_SUB_DEFAULT, __VA_ARGS__) #define M_GET_MUL(...) M_GET_METHOD(MUL, M_MUL_DEFAULT, __VA_ARGS__) @@ -2508,7 +2508,7 @@ static inline size_t m_core_cstr_hash(const char str[]) #define M_CALL_IT_CREF(oplist, ...) M_APPLY_API(M_GET_IT_CREF oplist, oplist, __VA_ARGS__) #define M_CALL_IT_REMOVE(oplist, ...) M_APPLY_API(M_GET_IT_REMOVE oplist, oplist, __VA_ARGS__) #define M_CALL_IT_INSERT(oplist, ...) M_APPLY_API(M_GET_IT_INSERT oplist, oplist, __VA_ARGS__) -#define M_CALL_TEST_EMPTY(oplist, ...) M_APPLY_API(M_GET_TEST_EMPTY oplist, oplist, __VA_ARGS__) +#define M_CALL_EMPTY_P(oplist, ...) M_APPLY_API(M_GET_EMPTY_P oplist, oplist, __VA_ARGS__) #define M_CALL_ADD(oplist, ...) M_APPLY_API(M_GET_ADD oplist, oplist, __VA_ARGS__) #define M_CALL_SUB(oplist, ...) M_APPLY_API(M_GET_SUB oplist, oplist, __VA_ARGS__) #define M_CALL_MUL(oplist, ...) M_APPLY_API(M_GET_MUL oplist, oplist, __VA_ARGS__) diff --git a/m-deque.h b/m-deque.h index 84dd76a2..2f4075e2 100644 --- a/m-deque.h +++ b/m-deque.h @@ -995,7 +995,7 @@ ,SWAP(M_C(name, _swap)) \ ,TYPE(M_C(name,_ct)) \ ,SUBTYPE(M_C(name, _subtype_ct)) \ - ,TEST_EMPTY(M_C(name,_empty_p)) \ + ,EMPTY_P(M_C(name,_empty_p)) \ ,IT_TYPE(M_C(name,_it_ct)) \ ,IT_FIRST(M_C(name,_it)) \ ,IT_LAST(M_C(name,_it_last)) \ diff --git a/m-dict.h b/m-dict.h index 9e41ad71..4e0b8478 100644 --- a/m-dict.h +++ b/m-dict.h @@ -1076,7 +1076,7 @@ CLEAN(M_C(name, _clean)), \ TYPE(M_C(name, _ct)), \ SUBTYPE(M_C(name, _subtype_ct)), \ - TEST_EMPTY(M_C(name,_empty_p)), \ + EMPTY_P(M_C(name,_empty_p)), \ IT_TYPE(M_C(name, _it_ct)), \ IT_FIRST(M_C(name,_it)), \ IT_SET(M_C(name, _it_set)), \ @@ -1131,7 +1131,7 @@ CLEAN(M_C(name, _clean)), \ TYPE(M_C(name, _ct)), \ SUBTYPE(M_C(name, _subtype_ct)), \ - TEST_EMPTY(M_C(name,_empty_p)), \ + EMPTY_P(M_C(name,_empty_p)), \ PUSH(M_C(name,_push)), \ KEY_TYPE(M_C(name, _key_ct)), \ VALUE_TYPE(M_C(name, _key_ct)), \ diff --git a/m-i-list.h b/m-i-list.h index de3d7258..e9534d51 100644 --- a/m-i-list.h +++ b/m-i-list.h @@ -104,7 +104,7 @@ typedef struct ilist_head_s { TYPE(M_C(name,_ct)), \ CLEAN(M_C(name,_clean)), \ SUBTYPE(M_C(name,_subtype_ct)), \ - TEST_EMPTY(M_C(name,_empty_p)), \ + EMPTY_P(M_C(name,_empty_p)), \ IT_TYPE(M_C(name,_it_ct)), \ IT_FIRST(M_C(name,_it)), \ IT_SET(M_C(name,_it_set)), \ diff --git a/m-list.h b/m-list.h index dcb547bf..4fd40633 100644 --- a/m-list.h +++ b/m-list.h @@ -103,7 +103,7 @@ SWAP(M_C(name, _swap)), \ TYPE(M_C(name,_ct)), \ SUBTYPE(M_C(name,_subtype_ct)), \ - TEST_EMPTY(M_C(name,_empty_p)), \ + EMPTY_P(M_C(name,_empty_p)), \ IT_TYPE(M_C(name, _it_ct)), \ IT_FIRST(M_C(name,_it)), \ IT_END(M_C(name,_it_end)), \ diff --git a/m-prioqueue.h b/m-prioqueue.h index 59c63506..a4ddcda0 100644 --- a/m-prioqueue.h +++ b/m-prioqueue.h @@ -90,7 +90,7 @@ ,PUSH(M_C(name,_push)) \ ,POP(M_C(name,_pop)) \ ,OPLIST(oplist) \ - ,TEST_EMPTY(M_C(name, _empty_p)), \ + ,EMPTY_P(M_C(name, _empty_p)), \ ,GET_SIZE(M_C(name, _size)) \ ,IT_TYPE(M_C(name, _it_ct)), \ IT_FIRST(M_C(name,_it)), \ diff --git a/m-rbtree.h b/m-rbtree.h index 88e25cde..3868b34c 100644 --- a/m-rbtree.h +++ b/m-rbtree.h @@ -86,7 +86,7 @@ SWAP(M_C(name, _swap)), \ TYPE(M_C(name,_ct)), \ SUBTYPE(M_C(name, _subtype_ct)), \ - TEST_EMPTY(M_C(name,_empty_p)), \ + EMPTY_P(M_C(name,_empty_p)), \ GET_SIZE(M_C(name, _size)), \ IT_TYPE(M_C(name, _it_ct)), \ IT_FIRST(M_C(name,_it)), \ diff --git a/m-string.h b/m-string.h index a9bff87a..aad40c70 100644 --- a/m-string.h +++ b/m-string.h @@ -1791,7 +1791,7 @@ namespace m_string { INIT_WITH(STRINGI_INIT_WITH), \ INIT_MOVE(string_init_move), MOVE(string_move), \ SWAP(string_swap), CLEAN(string_clean), \ - TEST_EMPTY(string_empty_p), \ + EMPTY_P(string_empty_p), \ CLEAR(string_clear), HASH(string_hash), EQUAL(string_equal_p), \ CMP(string_cmp), TYPE(string_t), \ PARSE_STR(string_parse_str), GET_STR(string_get_str), \ diff --git a/m-variant.h b/m-variant.h index 055d8bfe..101325f9 100644 --- a/m-variant.h +++ b/m-variant.h @@ -741,7 +741,7 @@ CLEAR(M_C(name, _clear)), \ CLEAN(M_C(name, _clean)), \ TYPE(M_C(name,_ct)), \ - TEST_EMPTY(M_C(name,_empty_p)), \ + EMPTY_P(M_C(name,_empty_p)), \ M_IF_METHOD_ALL(HASH, __VA_ARGS__)(HASH(M_C(name, _hash)),), \ M_IF_METHOD_ALL(EQUAL, __VA_ARGS__)(EQUAL(M_C(name, _equal_p)),), \ M_IF_METHOD_ALL(GET_STR, __VA_ARGS__)(GET_STR(M_C(name, _get_str)),), \