/cvmfs/atlas.cern.ch/repo/sw/ASG/AnalysisBase/2.4.30/CxxUtils/CxxUtils/libcalg/avl-tree.h File Reference
Balanced binary tree.
More...
Go to the source code of this file.
Detailed Description
Balanced binary 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 avl_tree_new. To destroy an AVL tree, use avl_tree_free.
To insert a new key-value pair into an AVL tree, use avl_tree_insert. To remove an entry from an AVL tree, use avl_tree_remove or avl_tree_remove_node.
To search an AVL tree, use avl_tree_lookup or avl_tree_lookup_node.
Tree nodes can be queried using the avl_tree_node_child, avl_tree_node_parent, avl_tree_node_key and avl_tree_node_value functions.
Define Documentation
#define AVL_TREE_NULL ((void *) 0) |
Typedef Documentation
Type of function used to compare keys in an AVL tree.
- Parameters:
-
| value1 | The first key. |
| value2 | The second key. |
- Returns:
- A negative number if value1 should be sorted before value2, a positive number if value2 should be sorted before value1, zero if the two keys are equal.
Enumeration Type Documentation
Function Documentation
void avl_tree_free |
( |
AVLTree * |
tree |
) |
|
Destroy an AVL tree.
- Parameters:
-
| tree | The tree to destroy. |
Insert a new key-value pair into an AVL tree.
- Parameters:
-
| tree | The tree. |
| key | The key to insert. |
| value | The value to insert. |
- Returns:
- The newly created tree node containing the key and value, or NULL if it was not possible to allocate the new memory.
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 avl_tree_lookup_node, except that the value at the node is returned rather than the node itself.
- Parameters:
-
| tree | The AVL tree to search. |
| key | The key to search for. |
- Returns:
- The value associated with the given key, or AVL_TREE_NULL if no entry with the given key is found.
Search an AVL tree for a node with a particular key. This uses the tree as a mapping.
- Parameters:
-
| tree | The AVL tree to search. |
| key | The key to search for. |
- Returns:
- The tree node containing the given key, or NULL if no entry with the given key is found.
Create a new AVL tree.
- Parameters:
-
| compare_func | Function to use when comparing keys in the tree. |
- Returns:
- A new AVL tree, or NULL if it was not possible to allocate the memory.
Find the child of a given tree node.
- Parameters:
-
| node | The tree node. |
| side | Which child node to get (left or right) |
- Returns:
- The child of the tree node, or NULL if the node has no child on the given side.
Retrieve the key for a given tree node.
- Parameters:
-
- Returns:
- The key to the given node.
Find the parent node of a given tree node.
- Parameters:
-
- Returns:
- The parent node of the tree node, or NULL if this is the root node.
Retrieve the value at a given tree node.
- Parameters:
-
- Returns:
- The value at the given node.
int avl_tree_num_entries |
( |
AVLTree * |
tree |
) |
|
Retrieve the number of entries in the tree.
- Parameters:
-
- Returns:
- The number of key-value pairs stored in the tree.
Remove an entry from a tree, specifying the key of the node to remove.
- Parameters:
-
| tree | The tree. |
| key | The key of the node to remove. |
- Returns:
- Zero (false) if no node with the specified key was found in the tree, non-zero (true) if a node with the specified key was removed.
Remove a node from a tree.
- Parameters:
-
| tree | The tree. |
| node | The node to remove |
Find the root node of a tree.
- Parameters:
-
- Returns:
- The root node of the tree, or NULL if the tree is empty.
Find the height of a subtree.
- Parameters:
-
| node | The root node of the subtree. |
- Returns:
- The height of the subtree.
Convert the keys in an AVL tree into a C array. This allows the tree to be used as an ordered set.
- Parameters:
-
- Returns:
- A newly allocated C array containing all the keys in the tree, in order. The length of the array is equal to the number of entries in the tree (see avl_tree_num_entries).