From aace904fb85cd440b849892818ff287b3ce62d1f Mon Sep 17 00:00:00 2001 From: Robert Spalek Date: Mon, 10 Jan 2005 16:03:15 +0000 Subject: [PATCH] added TREE_WANT_BOUNDARY for finding the first/last node --- lib/redblack.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/redblack.h b/lib/redblack.h index 764ca104..7658f25f 100644 --- a/lib/redblack.h +++ b/lib/redblack.h @@ -68,6 +68,8 @@ * Implies TREE_DUPLICATES. * TREE_WANT_SEARCH node *search(key) -- find the node with the specified * or, if it does not exist, the nearest one. + * TREE_WANT_BOUNDARY node *boundary(uns direction) -- finds smallest + * (direction==0) or largest (direction==1) node. * TREE_WANT_ADJACENT node *adjacent(node *, uns direction) -- finds next * (direction==1) or previous (direction==0) node. * TREE_WANT_NEW node *new(key) -- create new node with given key. @@ -410,6 +412,22 @@ STATIC P(node) * P(find) (T *t, TREE_KEY_DECL) } #endif +#ifdef TREE_WANT_BOUNDARY +STATIC P(node) * P(boundary) (T *t, uns direction) +{ + P(bucket) *n = t->root, *ns; + if (!n) + return NULL; + else + { + uns son = !!direction; + while ((ns = P(tree_son) (n, son))) + n = ns; + return &n->n; + } +} +#endif + #ifdef TREE_STORE_PARENT STATIC P(node) * P(adjacent) (P(node) *start, uns direction) { @@ -966,6 +984,7 @@ do \ #undef TREE_WANT_FIND #undef TREE_WANT_FIND_NEXT #undef TREE_WANT_SEARCH +#undef TREE_WANT_BOUNDARY #undef TREE_WANT_ADJACENT #undef TREE_WANT_NEW #undef TREE_WANT_LOOKUP -- 2.39.2