diff --git a/README.md b/README.md index 07268b0f..9e8f0734 100644 --- a/README.md +++ b/README.md @@ -2634,10 +2634,14 @@ Return true if 'it' references no longer a valid element. Return true if 'it' references the last element or is no longer valid. -##### bool name\_to\_p(const name\it_\_t it, const type data) +##### bool name\_it\_until\_p(const name\it_\_t it, const type data) Return true if 'it' references an element that is greater or equal than 'data'. +##### bool name\_it\_while\_p(const name\it_\_t it, const type data) + +Return true if 'it' references an element that is lower or equal than 'data'. + ##### void name\_next(name\it_\_t it) Update the iterator 'it' to the next element. @@ -2893,10 +2897,14 @@ lower of equal than 'data' or the first element is there is none. Return true if 'it' references no longer a valid element. -##### bool name\_to\_p(const name\_it_\_t it, const type data) +##### bool name\_it\_until\_p(const name\_it_\_t it, const type data) Return true if 'it' references an element that is greater or equal than 'data'. +##### bool name\_it\_while\_p(const name\_it_\_t it, const type data) + +Return true if 'it' references an element that is lower or equal than 'data'. + ##### bool name\_it\_equal\_p(const name\_it_\_t it1, const name\_it_\_t it1) Return true if both iterators reference the same object. diff --git a/doc/API.txt b/doc/API.txt index 3d7436bc..7bbd5363 100644 --- a/doc/API.txt +++ b/doc/API.txt @@ -37,3 +37,5 @@ V0.2.*: * worker_start takes a 'worker_t' as an additional parameter V0.3.*: * Remove B+TREE _remove method as it has been deprecated (use _erase instead) * Remove DICT _remove method as it has been deprecated (use _erase instead) + * Make _it_to_p method of B+TREE / RB-TREE as deprecated (uses _it_until_p instead ). + diff --git a/m-bptree.h b/m-bptree.h index 927cb317..2247c72b 100644 --- a/m-bptree.h +++ b/m-bptree.h @@ -864,7 +864,7 @@ } \ \ static inline bool \ - M_C(name, _it_to_p)(it_t it, key_t const key) \ + M_C(name, _it_until_p)(it_t it, key_t const key) \ { \ assert (it != NULL); \ node_t n = it->node; \ @@ -873,6 +873,22 @@ return (cmp >= 0); \ } \ \ + static inline bool \ + M_C(name, _it_while_p)(it_t it, key_t const key) \ + { \ + assert (it != NULL); \ + node_t n = it->node; \ + if (it->idx >= -n->num) return true; \ + int cmp = M_CALL_CMP(key_oplist, n->key[it->idx], key); \ + return (cmp <= 0); \ + } \ + \ + static inline bool M_ATTR_DEPRECATED \ + M_C(name, _it_to_p)(it_t it, key_t const key) \ + { \ + return M_C(name, _it_until_p)(it, key); \ + } \ + \ static inline value_t * \ M_C(name, _min)(const tree_t b) \ { \ diff --git a/m-rbtree.h b/m-rbtree.h index 432bc8f8..aacc20cb 100644 --- a/m-rbtree.h +++ b/m-rbtree.h @@ -513,7 +513,7 @@ typedef enum { } \ \ static inline bool \ - M_C(name, _it_to_p)(it_t it, type const data) \ + M_C(name, _it_until_p)(it_t it, type const data) \ { \ assert (it != NULL); \ if (it->cpt == 0) return true; \ @@ -523,6 +523,23 @@ typedef enum { return (cmp >= 0); \ } \ \ + static inline bool \ + M_C(name, _it_while_p)(it_t it, type const data) \ + { \ + assert (it != NULL); \ + if (it->cpt == 0) return true; \ + assert (it->cpt > 0 && it->cpt < RBTREEI_MAX_STACK); \ + node_t *n = it->stack[it->cpt-1]; \ + int cmp = M_CALL_CMP(oplist, n->data, data); \ + return (cmp <= 0); \ + } \ + \ + static inline bool M_ATTR_DEPRECATED \ + M_C(name, _it_to_p)(it_t it, type const data) \ + { \ + return M_C(name, _it_until_p)(it, data); \ + } \ + \ static inline type * \ M_C(name, _min)(const tree_t tree) \ { \ diff --git a/tests/test-mbptree.c b/tests/test-mbptree.c index af9a7047..29a30d28 100644 --- a/tests/test-mbptree.c +++ b/tests/test-mbptree.c @@ -282,7 +282,7 @@ static void test5(void) assert (btree_it_equal_p(it, it2)); i = 500; - for(btree_it_from(it, b, 500); !btree_it_to_p(it, 600); btree_next(it)) { + for(btree_it_from(it, b, 500); !btree_it_until_p(it, 600); btree_next(it)) { const btree_type_t *item = btree_cref(it); assert (*item->key_ptr == i); assert (*item->value_ptr == 1000*i); @@ -292,7 +292,7 @@ static void test5(void) btree_erase (b, 500); i = 501; - for(btree_it_from(it, b, 500); !btree_it_to_p(it, 600); btree_next(it)) { + for(btree_it_from(it, b, 500); !btree_it_until_p(it, 600); btree_next(it)) { const btree_type_t *item = btree_cref(it); assert (*item->key_ptr == i); assert (*item->value_ptr == 1000*i); @@ -302,7 +302,7 @@ static void test5(void) btree_it_from(it, b, 1000); assert (btree_end_p(it)); - assert (btree_it_to_p(it, 1001)); + assert (btree_it_until_p(it, 1001)); btree_clear(b); }