diff options
author | Ronnie Sahlberg <sahlberg@ronnie> | 2007-08-08 11:21:18 +1000 |
---|---|---|
committer | Ronnie Sahlberg <sahlberg@ronnie> | 2007-08-08 11:21:18 +1000 |
commit | c1bfda5772c73d41907beb193cb5a58f822d1a53 (patch) | |
tree | de82705f7595d8578f0ef616db37c598d052cd7b /ctdb/common/rb_tree.h | |
parent | 26d3cd38a92dc29f25943231ebf7315062298319 (diff) | |
download | samba-c1bfda5772c73d41907beb193cb5a58f822d1a53.tar.gz samba-c1bfda5772c73d41907beb193cb5a58f822d1a53.tar.xz samba-c1bfda5772c73d41907beb193cb5a58f822d1a53.zip |
add a tree insert function that takes a callback fucntion to populate
the data of the tree.
this callback makes it more convenient to manage cases where one might
want to insert multiple entries into the tree with the same key
rename the tree->tree pointer to tree->root since this is supposed to
point to the root of the tree
add a small test utility
(This used to be ctdb commit f6313bed9c53e0d1c36c9e08ac707e88e2a4fcd5)
Diffstat (limited to 'ctdb/common/rb_tree.h')
-rw-r--r-- | ctdb/common/rb_tree.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/ctdb/common/rb_tree.h b/ctdb/common/rb_tree.h index 603ebfad34..ad095dd50f 100644 --- a/ctdb/common/rb_tree.h +++ b/ctdb/common/rb_tree.h @@ -32,7 +32,7 @@ typedef struct _trbt_node_t { } trbt_node_t; typedef struct _trbt_tree_t { - trbt_node_t *tree; + trbt_node_t *root; } trbt_tree_t; @@ -49,7 +49,17 @@ void *trbt_lookup32(trbt_tree_t *tree, uint32_t key); */ void *trbt_insert32(trbt_tree_t *tree, uint32_t key, void *data); +/* Insert a new node into the tree. + If this is a new node: + callback is called with data==NULL and param=param + the returned value from the callback is talloc_stolen and inserted in the + tree. + If a node already exists for this key then: + callback is called with data==existing data and param=param + the returned calue is talloc_stolen and inserted in the tree +*/ +void trbt_insert32_callback(trbt_tree_t *tree, uint32_t key, void *(*callback)(void *param, void *data), void *param); + /* Delete a node from the tree and free all data associated with it */ void trbt_delete32(trbt_tree_t *tree, uint32_t key); - |