]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add first / last API
authorAlan T. DeKok <aland@freeradius.org>
Wed, 6 Mar 2024 14:18:47 +0000 (09:18 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 6 Mar 2024 14:21:56 +0000 (09:21 -0500)
src/lib/util/rb.c
src/lib/util/rb.h

index a7377cff8181a068bc29b48e5b8787068205babf..a94d2f630d9dc8356150a9729c6dc6c686a9bedd 100644 (file)
@@ -777,6 +777,36 @@ uint32_t fr_rb_num_elements(fr_rb_tree_t *tree)
        return tree->num_elements;
 }
 
+void *fr_rb_first(fr_rb_tree_t *tree)
+{
+       fr_rb_node_t *x = tree->root;
+
+       if (x == NIL) return NULL;
+
+       /*
+        *      First node is the leftmost
+        */
+       while (x->left != NIL) x = x->left;
+
+       return x->data;
+}
+
+
+void *fr_rb_last(fr_rb_tree_t *tree)
+{
+       fr_rb_node_t *x = tree->root;
+
+       if (x == NIL) return NULL;
+
+       /*
+        *      Last node is the rightmost
+        */
+       while (x->right != NIL) x = x->right;
+
+       return x->data;
+}
+
+
 /** Initialise an in-order iterator
  *
  * @param[out] iter    to initialise.
index 28f874dffcf617e3501ba1fb32d36ecd27dc602e..0fe56ccec7ab455556b89432090c9e3b46a55766 100644 (file)
@@ -295,6 +295,10 @@ bool               fr_rb_delete_by_inline_node(fr_rb_tree_t *tree, fr_rb_node_t *node) CC_HI
 
 uint32_t       fr_rb_num_elements(fr_rb_tree_t *tree) CC_HINT(nonnull);
 
+void           *fr_rb_first(fr_rb_tree_t *tree) CC_HINT(nonnull);
+
+void           *fr_rb_last(fr_rb_tree_t *tree) CC_HINT(nonnull);
+
 /** Check to see if an item is in a tree by examining its inline #fr_rb_node_t
  *
  * This works because we use NIL sentinels to represent the absence of a child