Data Structures | |
struct | di_tree |
Tree. More... | |
struct | di_tree_node |
Node of a tree. More... | |
Functions | |
di_tree * | di_tree_new (di_compare_func key_compare_func) |
di_tree * | di_tree_new_full (di_compare_func key_compare_func, di_destroy_notify key_destroy_func, di_destroy_notify value_destroy_func) |
void | di_tree_destroy (di_tree *tree) |
void | di_tree_insert (di_tree *tree, void *key, void *value) |
void * | di_tree_lookup (di_tree *tree, const void *key) |
void | di_tree_foreach (di_tree *tree, di_hfunc *func, void *user_data) |
di_ksize_t | di_tree_size (di_tree *tree) |
|
Destroys the di_tree. If keys and/or values are dynamically allocated, you should either free them first or create the di_tree using di_tree_new_full. In the latter case the destroy functions you supplied will be called on all keys and values before destroying the di_hash_table.
|
|
Calls the given function for each of the key/value pairs in the di_tree. The function is passed the key and value of each pair, and the given user_data parameter.
00274 { 00275 di_tree_node_foreach (tree->root, func, user_data); 00276 }
|
|
Inserts a new key and value into a di_tree. If the key already exists in the di_tree its current value is replaced with the new value. If you supplied a value_destroy_func when creating the di_tree, the old value is freed using that function. If you supplied a key_destroy_func when creating the di_tree, the passed key is freed using that function.
00254 { 00255 if (!tree->root) 00256 { 00257 tree->root = di_tree_node_new (key, value); 00258 tree->nnodes++; 00259 } 00260 else 00261 tree->root = di_tree_node_insert (tree, tree->root, key, value); 00262 }
|
|
Looks up a key in a di_tree.
00301 { 00302 return di_tree_node_lookup (tree, tree->root, key); 00303 }
|
|
Creates a new di_tree.
00068 { 00069 return di_tree_new_full (key_compare_func, NULL, NULL); 00070 }
|
|
Creates a new di_tree like di_tree_new and allows to specify functions to free the memory allocated for the key and value that get called when removing the entry from the di_tree
00073 { 00074 di_tree *tree; 00075 00076 tree = di_new (di_tree, 1); 00077 tree->nnodes = 0; 00078 tree->key_compare_func = key_compare_func; 00079 tree->key_destroy_func = key_destroy_func; 00080 tree->value_destroy_func = value_destroy_func; 00081 tree->root = 0; 00082 00083 return tree; 00084 }
|
|
Returns the number of elements contained in the di_tree.
00279 { 00280 return tree->nnodes; 00281 }
|