Merge branch '1.3' of 10.1.1.27:/shared/ctdb/ctdb-git into 1.3
[sahlberg/ctdb.git] / common / rb_tree.h
index 9c470aee9648184707b8662726ef04c64e3e2848..eef0bc5227a92dd8b126f8098ec7720523b59232 100644 (file)
 
 #define TRBT_RED               0x00
 #define TRBT_BLACK             0x01
-typedef struct _trbt_node_t {
-       struct _trbt_tree_t *tree;
-       struct _trbt_node_t *parent;
-       struct _trbt_node_t *left;
-       struct _trbt_node_t *right;
+typedef struct trbt_node {
+       struct trbt_tree *tree;
+       struct trbt_node *parent;
+       struct trbt_node *left;
+       struct trbt_node *right;
        uint32_t rb_color;
        uint32_t key32;
        void *data;
 } trbt_node_t;
 
-typedef struct _trbt_tree_t {
+typedef struct trbt_tree {
        trbt_node_t *root;
+/* automatically free the tree when the last node has been deleted */
+#define TRBT_AUTOFREE          0x00000001
+       uint32_t flags;
 } trbt_tree_t;
 
 
 
 /* Create a RB tree */
-trbt_tree_t *trbt_create(TALLOC_CTX *memctx);
+trbt_tree_t *trbt_create(TALLOC_CTX *memctx, uint32_t flags);
 
 /* Lookup a node in the tree and return a pointer to data or NULL */
 void *trbt_lookup32(trbt_tree_t *tree, uint32_t key);
@@ -71,9 +74,9 @@ void trbt_insertarray32_callback(trbt_tree_t *tree, uint32_t keylen, uint32_t *k
    and return a pointer to data or NULL */
 void *trbt_lookuparray32(trbt_tree_t *tree, uint32_t keylen, uint32_t *key);
 
-/* Delete a node in the tree with a key based on an array of uint32 
-   and return a pointer to data or NULL */
-void trbt_deletearray32(trbt_tree_t *tree, uint32_t keylen, uint32_t *key);
-
 /* Traverse a tree with a key based on an array of uint32 */
 void trbt_traversearray32(trbt_tree_t *tree, uint32_t keylen, void (*callback)(void *param, void *data), void *param);
+
+/* Lookup the first node in the tree with a key based on an array of uint32 
+   and return a pointer to data or NULL */
+void *trbt_findfirstarray32(trbt_tree_t *tree, uint32_t keylen);