LVS
[sahlberg/ctdb.git] / common / rb_tree.c
index 9876f654a322ee4869f5d5fe506fbcd70cfdfb71..b2c2ee83d5036dd99d035882e76b1da553f6346b 100644 (file)
@@ -21,7 +21,7 @@
 #include "rb_tree.h"
 
 #define NO_MEMORY_FATAL(p) do { if (!(p)) { \
-          DEBUG(0,("Out of memory for %s at %s\n", #p, __location__)); \
+          DEBUG(DEBUG_CRIT,("Out of memory for %s at %s\n", #p, __location__)); \
          exit(10); \
          }} while (0)
 
@@ -962,6 +962,43 @@ trbt_traversearray32(trbt_tree_t *tree, uint32_t keylen,
 }
 
 
+/* this function will return the first node in a tree where
+   the key is an array of uint32_t
+*/
+void *
+trbt_findfirstarray32(trbt_tree_t *tree, uint32_t keylen)
+{
+       trbt_node_t *node;
+
+       if (keylen < 1) {
+               return NULL;
+       }
+       
+       if (tree == NULL) {
+               return NULL;
+       }
+
+       node=tree->root;
+       if (node == NULL) {
+               return NULL;
+       }
+
+       while (node->left) {
+               node = node->left;
+       }
+
+       /* we found our node so return the data */
+       if (keylen == 1) {
+               return node->data;
+       }
+
+       /* we are still traversing subtrees so find the first node in the
+          next level of trees
+       */
+       return trbt_findfirstarray32(node->data, keylen-1);
+}
+
+
 #if 0
 static void printtree(trbt_node_t *node, int levels)
 {