From 826d251ffe55ce56227a051692c405f6c313d79c Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Thu, 28 Oct 2021 17:55:54 +0200 Subject: [PATCH] Rename RBTREE & BPTREE _clean in _reset to avoid confusing _clean & _clear functions. See #97 --- README.md | 8 ++++---- m-bptree.h | 19 ++++++++++++------- m-rbtree.h | 18 ++++++++++++------ tests/test-mbptree.c | 2 +- tests/test-mrbtree.c | 2 +- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index fefee98f..f39cfac7 100644 --- a/README.md +++ b/README.md @@ -2992,9 +2992,9 @@ from 'ref' and clear 'ref'. Set the Red Black Tree 'rbtree' by stealing as resource as possible from 'ref' and clear 'ref'. -##### void name\_clean(name\_t rbtree) +##### void name\_reset(name\_t rbtree) -Clean the Red Black Tree 'rbtree'. 'rbtree' remains initialized but empty. +Reset the Red Black Tree 'rbtree' (It remains initialized but empty). ##### size\_t name\_size(const name\_t rbtree) @@ -3316,9 +3316,9 @@ from 'ref' and clear 'ref'. Set the B+Tree 'tree' by stealing as resource as possible from 'ref' and clear 'ref'. -##### void name\_clean(name\_t tree) +##### void name\_reset(name\_t tree) -Clean the B+Tree 'tree'. 'tree' remains initialized but empty. +Reset the B+Tree 'tree' (It remains initialized but empty). ##### size\_t name\_size(const name\_t tree) diff --git a/m-bptree.h b/m-bptree.h index f25ef411..1d8f8170 100644 --- a/m-bptree.h +++ b/m-bptree.h @@ -175,7 +175,7 @@ IT_NEXT(M_C(name,_next)), \ IT_REF(M_C(name,_ref)), \ IT_CREF(M_C(name,_cref)), \ - CLEAN(M_C(name,_clean)), \ + CLEAN(M_C(name,_reset)), \ PUSH(M_C(name,_push)), \ GET_MIN(M_C(name,_min)), \ GET_MAX(M_C(name,_max)), \ @@ -227,7 +227,7 @@ IT_EQUAL_P(M_C(name,_it_equal_p)), \ IT_NEXT(M_C(name,_next)), \ IT_CREF(M_C(name,_cref)), \ - CLEAN(M_C(name,_clean)), \ + CLEAN(M_C(name,_reset)), \ GET_MIN(M_C(name,_min)), \ GET_MAX(M_C(name,_max)), \ KEY_TYPE(M_C(name, _key_ct)), \ @@ -432,7 +432,7 @@ return num; \ } \ \ - static inline void M_C(name, _clean)(tree_t b) \ + static inline void M_C(name, _reset)(tree_t b) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ node_t next, n = b->root; \ @@ -475,10 +475,15 @@ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ } \ \ + static inline void M_ATTR_DEPRECATED M_C(name, _clean)(tree_t b) \ + { \ + M_C(name, _reset)(b); \ + } \ + \ static inline void M_C(name, _clear)(tree_t b) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ - M_C(name, _clean)(b); \ + M_C(name, _reset)(b); \ /* Once the tree is clean, only the root remains */ \ M_CALL_DEL(key_oplist, b->root); \ b->root = NULL; \ @@ -1307,7 +1312,7 @@ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, t1); \ M_ASSERT (str != NULL); \ - M_C(name,_clean)(t1); \ + M_C(name,_reset)(t1); \ bool success = false; \ int c = *str++; \ if (M_UNLIKELY (c != '[')) goto exit; \ @@ -1349,7 +1354,7 @@ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, t1); \ M_ASSERT (file != NULL); \ - M_C(name,_clean)(t1); \ + M_C(name,_reset)(t1); \ int c = fgetc(file); \ if (M_UNLIKELY (c != '[')) return false; \ c = fgetc(file); \ @@ -1435,7 +1440,7 @@ m_serial_return_code_t ret; \ size_t estimated_size = 0; \ key_t key; \ - M_C(name,_clean)(t1); \ + M_C(name,_reset)(t1); \ M_IF(isMap)( \ value_t value; \ ret = f->m_interface->read_map_start(local, f, &estimated_size); \ diff --git a/m-rbtree.h b/m-rbtree.h index db60ab70..525bebda 100644 --- a/m-rbtree.h +++ b/m-rbtree.h @@ -97,7 +97,7 @@ IT_PREVIOUS(M_C(name,_previous)), \ IT_CREF(M_C(name,_cref)), \ IT_REMOVE(M_C(name,_remove)), \ - CLEAN(M_C(name,_clean)), \ + CLEAN(M_C(name,_reset)), \ PUSH(M_C(name,_push)), \ GET_MIN(M_C(name,_min)), \ GET_MAX(M_C(name,_max)), \ @@ -250,7 +250,7 @@ typedef enum { } \ \ static inline void \ - M_C(name, _clean)(tree_t tree) \ + M_C(name, _reset)(tree_t tree) \ { \ M_RBTR33_CONTRACT(tree); \ node_t *stack[M_RBTR33_MAX_STACK]; \ @@ -294,11 +294,17 @@ typedef enum { tree->size = 0; \ } \ \ + static inline void M_ATTR_DEPRECATED \ + M_C(name, _clean)(tree_t tree) \ + { \ + M_C(name,_reset)(tree); \ + } \ + \ static inline void \ M_C(name, _clear)(tree_t tree) \ { \ /* Nothing more than clean the tree as everything is cleared */ \ - M_C(name, _clean)(tree); \ + M_C(name, _reset)(tree); \ } \ \ static inline void \ @@ -1063,7 +1069,7 @@ typedef enum { { \ M_RBTR33_CONTRACT(rbtree); \ M_ASSERT (str != NULL); \ - M_C(name,_clean)(rbtree); \ + M_C(name,_reset)(rbtree); \ bool success = false; \ int c = *str++; \ if (M_UNLIKELY (c != '[')) goto exit; \ @@ -1094,7 +1100,7 @@ typedef enum { { \ M_RBTR33_CONTRACT(rbtree); \ M_ASSERT (file != NULL); \ - M_C(name,_clean)(rbtree); \ + M_C(name,_reset)(rbtree); \ int c = fgetc(file); \ if (M_UNLIKELY (c != '[')) return false; \ c = fgetc(file); \ @@ -1150,7 +1156,7 @@ typedef enum { m_serial_return_code_t ret; \ size_t estimated_size = 0; \ type key; \ - M_C(name,_clean)(t1); \ + M_C(name,_reset)(t1); \ ret = f->m_interface->read_array_start(local, f, &estimated_size); \ if (M_UNLIKELY (ret != M_SERIAL_OK_CONTINUE)) return ret; \ M_CALL_INIT(oplist, key); \ diff --git a/tests/test-mbptree.c b/tests/test-mbptree.c index c4b2ccbc..54ee37fe 100644 --- a/tests/test-mbptree.c +++ b/tests/test-mbptree.c @@ -187,7 +187,7 @@ static void test2(void) assert (k == -2); r = btree_pop_at(NULL, b, 0); assert (r == false); - btree_clean(b); + btree_reset(b); assert (btree_size(b) == 0); assert (btree_empty_p(b)); btree_clear(b); diff --git a/tests/test-mrbtree.c b/tests/test-mrbtree.c index f6c53e18..e57d8f36 100644 --- a/tests/test-mrbtree.c +++ b/tests/test-mrbtree.c @@ -266,7 +266,7 @@ static void test_uint(void) rbtree_uint_init (tree); assert(rbtree_uint_empty_p(tree)); - rbtree_uint_clean(tree2); + rbtree_uint_reset(tree2); rbtree_uint_push(tree2, 17421); assert(rbtree_uint_size(tree2) == 1); rbtree_uint_swap(tree, tree2);