Typedefs | |
typedef _AVLTree | AVLTree |
An AVL tree balanced binary tree. | |
typedef _AVLTreeNode | AVLTreeNode |
A node in an AVL tree. | |
typedef int(* | AVLTreeCompareFunc )(void *data1, void *data2) |
Type of function used to compare keys in an AVL tree. | |
Functions | |
AVLTree * | avltree_new (AVLTreeCompareFunc compare_func) |
Create a new AVL tree. | |
void | avltree_free (AVLTree *tree) |
Destroy an AVL tree. | |
AVLTreeNode * | avltree_insert (AVLTree *tree, void *key, void *value) |
Insert a new key-value pair into an AVL tree. | |
void | avltree_remove_node (AVLTree *tree, AVLTreeNode *node) |
Remove a node from a tree. | |
int | avltree_remove (AVLTree *tree, void *key) |
Remove an entry from a tree, specifying the key of the node to remove. | |
AVLTreeNode * | avltree_lookup_node (AVLTree *tree, void *key) |
Search an AVL tree for a node with a particular key. | |
void * | avltree_lookup (AVLTree *tree, void *key) |
Search an AVL tree for a value corresponding to a particular key. | |
AVLTreeNode * | avltree_root_node (AVLTree *tree) |
Find the root node of a tree. | |
void * | avltree_node_key (AVLTreeNode *node) |
Retrieve the key for a given tree node. | |
void * | avltree_node_value (AVLTreeNode *node) |
Retrieve the value at a given tree node. | |
AVLTreeNode * | avltree_node_left_child (AVLTreeNode *node) |
Find the left child of a given tree node. | |
AVLTreeNode * | avltree_node_right_child (AVLTreeNode *node) |
Find the right child of a given tree node. | |
AVLTreeNode * | avltree_node_parent (AVLTreeNode *node) |
Find the parent node of a given tree node. | |
int | avltree_subtree_height (AVLTreeNode *node) |
Find the height of a subtree. | |
void ** | avltree_to_array (AVLTree *tree) |
Convert the keys in an AVL tree into a C array. | |
int | avltree_num_entries (AVLTree *tree) |
Retrieve the number of entries in the tree. |
The AVL tree structure is a balanced binary tree which stores a collection of nodes (see AVLTreeNode). Each node has a key and a value associated with it. The nodes are sorted within the tree based on the order of their keys. Modifications to the tree are constructed such that the tree remains balanced at all times (there are always roughly equal numbers of nodes on either side of the tree).
Balanced binary trees have several uses. They can be used as a mapping (searching for a value based on its key), or as a set of keys which is always ordered.
To create a new AVL tree, use avltree_new. To destroy an AVL tree, use avltree_free.
To insert a new key-value pair into an AVL tree, use avltree_insert. To remove an entry from an AVL tree, use avltree_remove or avltree_remove_node.
To search an AVL tree, use avltree_lookup or avltree_lookup_node.
Tree nodes can be queried using the avltree_node_left_child, avltree_node_right_child, avltree_node_parent, avltree_node_key and avltree_node_value functions.
|
An AVL tree balanced binary tree.
|
|
Type of function used to compare keys in an AVL tree.
|
|
A node in an AVL tree.
|
|
Destroy an AVL tree.
|
|
Insert a new key-value pair into an AVL tree.
|
|
Search an AVL tree for a value corresponding to a particular key. This uses the tree as a mapping. Note that this performs identically to avltree_lookup_node, except that the value at the node is returned rather than the node itself.
|
|
Search an AVL tree for a node with a particular key. This uses the tree as a mapping.
|
|
Create a new AVL tree.
|
|
Retrieve the key for a given tree node.
|
|
Find the left child of a given tree node.
|
|
Find the parent node of a given tree node.
|
|
Find the right child of a given tree node.
|
|
Retrieve the value at a given tree node.
|
|
Retrieve the number of entries in the tree.
|
|
Remove an entry from a tree, specifying the key of the node to remove.
|
|
Remove a node from a tree.
|
|
Find the root node of a tree.
|
|
Find the height of a subtree.
|
|
Convert the keys in an AVL tree into a C array. This allows the tree to be used as an ordered set.
|