Archived
1
0
Fork 0
This repository has been archived on 2026-05-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
archived/docs/technical/rbtree.txt
Henrik Hautakoski f46ae1970b Change indentation to follow the updated standard.
Alot of mixed indentation. use 4 chars wide soft tabs.
2011-03-19 12:28:48 +02:00

64 lines
1.5 KiB
Text

Red-Black Tree
--------------
Macros
~~~~~~
`RBTREE_INIT`::
Initialize a `rbtree` structure. +
should only be used with the declaration like:
+
----
rbtree tree = RBTREE_INIT(cmp);
----
+
will expand to set the compare function 'cmp' to the `cmp_fn` member.
Data structures
~~~~~~~~~~~~~~~
* `rbtree`
+
--
Structure that holds a tree of nodes
`root`::
Pointer to the node that is the root of the tree.
`cmp_fn`::
Pointer to the function that is used to compare two `key` pointers. +
Shall return a value greater than zero if 'ptr1' > 'ptr2', a value less than zero if 'ptr1' < 'ptr2' and zero if 'ptr1' == 'ptr2'.
--
Functions
~~~~~~~~~
`rbtree_insert()`::
Creates and inserts a new node in the tree. +
Returns a positive value if the node was inserted, zero if the key already exists in the tree and a negative value if an error occured.
NOTE: The memory pointed to by the 'key' pointer is *not* copied so you must ensure that it has a infinite lifetime.
`rbtree_delete()`::
Deletes a node from the tree. +
Returns the node's key if a node was removed, `NULL` otherwise.
`rbtree_free()`::
Deletes the whole tree. if provided, calls 'free_fn' for every node.
`rbtree_walk()`::
Walks the tree in-order and passes a pointer to `key`
for the given node to the 'action' callback function.
`rbtree_search()`::
Searches the tree for 'key'. +
Returns a pointer to the node if found else `NULL`.
`rbtree_is_empty()`::
Checks if a tree is empty, retruns zero if the tree is empty, nonzero otherwise.