From 00b9ee045c2a991ac4cfe87a9bd08866946b7a32 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Tue, 21 Mar 2017 23:16:51 +0100 Subject: [PATCH] Add it_set, it_from & it_to_p operators. --- m-algo.h | 2 +- m-rbtree.h | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/m-algo.h b/m-algo.h index 15cc4281..e10bd3c1 100644 --- a/m-algo.h +++ b/m-algo.h @@ -325,7 +325,7 @@ , /* NO_DIV METHOD */ ) \ \ -//TODO: const_iterator & CM_EACH missing... +//TODO: const_iterator missing... //TODO: Algorithm missing // nth_element, average, find_if, count_if, ... diff --git a/m-rbtree.h b/m-rbtree.h index 868b611c..8939b343 100644 --- a/m-rbtree.h +++ b/m-rbtree.h @@ -390,6 +390,14 @@ typedef enum { it->cpt = 0; \ } \ \ + static inline void \ + M_C3(rbtree_, name, _it_set)(M_C3(rbtree_it_, name,_t) it, \ + const M_C3(rbtree_it_, name,_t) ref) \ + { \ + assert (it != NULL && ref != NULL); \ + *it = *ref; \ + } \ + \ static inline bool \ M_C3(rbtree_, name, _end_p)(const M_C3(rbtree_it_, name,_t) it) \ { \ @@ -460,6 +468,42 @@ typedef enum { { \ return it1->cpt == it2->cpt \ && it1->stack[it1->cpt-1] == it2->stack[it2->cpt-1]; \ + } \ + \ + \ + static inline void \ + M_C3(rbtree_, name, _it_from)(M_C3(rbtree_it_, name,_t) it, \ + const M_C3(rbtree_, name,_t) tree, \ + type const data) \ + { \ + RBTREEI_CONTRACT (tree); \ + assert (it != NULL); \ + unsigned int cpt = 0; \ + node_t *n = tree->node; \ + it->stack[cpt] = n; \ + while (n != NULL) { \ + int cmp = M_GET_CMP oplist (n->data, data); \ + if (cmp == 0) \ + break; \ + int child = (cmp < 0); \ + it->which[cpt++] = child; \ + n = n->child[child]; \ + assert (cpt < RBTREEI_MAX_STACK); \ + it->stack[cpt] = n; \ + } \ + it->cpt = cpt; \ + } \ + \ + static inline bool \ + M_C3(rbtree_, name, _it_to_p)(M_C3(rbtree_it_, name,_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_GET_CMP oplist (n->data, data); \ + return (cmp >= 0); \ } \ \ static inline type * \ @@ -911,7 +955,6 @@ typedef enum { , /* no in_str */ ) \ \ -// TODO: missing specialized iterator functions (it_from, it_to) // TODO: specialized _sort shall do nothing, but shall check the requested order. How ?