ATLAS Offline Software
Loading...
Searching...
No Matches
avl-tree.h
Go to the documentation of this file.
1/*
2
3Copyright (c) 2005-2008, Simon Howard
4
5Permission to use, copy, modify, and/or distribute this software
6for any purpose with or without fee is hereby granted, provided
7that the above copyright notice and this permission notice appear
8in all copies.
9
10THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
14CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
16NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
17CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
19 */
20
53
54#ifndef ALGORITHM_AVLTREE_H
55#define ALGORITHM_AVLTREE_H
56
57#ifdef __cplusplus
58extern "C" {
59#endif
60
66
67typedef struct _AVLTree AVLTree;
68
72
73typedef void *AVLTreeKey;
74
78
79typedef void *AVLTreeValue;
80
84
85#define AVL_TREE_NULL ((void *) 0)
86
96
97typedef struct _AVLTreeNode AVLTreeNode;
98
102
107
118
119typedef int (*AVLTreeCompareFunc)(AVLTreeValue value1, AVLTreeValue value2);
120
128
130
136
138
149
151
158
160
171
173
183
185
198
200
208
210
217
219
226
228
237
239
247
249
256
258
269
271
278
280
281#ifdef __cplusplus
282}
283#endif
284
285#endif /* #ifndef ALGORITHM_AVLTREE_H */
286
AVLTreeNodeSide
An AVLTreeNode can have left and right children.
Definition avl-tree.h:103
@ AVL_TREE_NODE_LEFT
Definition avl-tree.h:104
@ AVL_TREE_NODE_RIGHT
Definition avl-tree.h:105
int avl_tree_num_entries(AVLTree *tree)
Retrieve the number of entries in the tree.
AVLTreeValue avl_tree_lookup(AVLTree *tree, AVLTreeKey key)
Search an AVL tree for a value corresponding to a particular key.
void avl_tree_free(AVLTree *tree)
Destroy an AVL tree.
AVLTreeNode * avl_tree_node_parent(AVLTreeNode *node)
Find the parent node of a given tree node.
int avl_tree_remove(AVLTree *tree, AVLTreeKey key)
Remove an entry from a tree, specifying the key of the node to remove.
AVLTree * avl_tree_new(AVLTreeCompareFunc compare_func)
Create a new AVL tree.
void * AVLTreeKey
A key for an AVLTree.
Definition avl-tree.h:73
AVLTreeNode * avl_tree_lookup_node(AVLTree *tree, AVLTreeKey key)
Search an AVL tree for a node with a particular key.
AVLTreeNode * avl_tree_node_child(AVLTreeNode *node, AVLTreeNodeSide side)
Find the child of a given tree node.
AVLTreeValue avl_tree_node_value(AVLTreeNode *node)
Retrieve the value at a given tree node.
int avl_tree_subtree_height(AVLTreeNode *node)
Find the height of a subtree.
AVLTreeNode * avl_tree_root_node(AVLTree *tree)
Find the root node of a tree.
struct _AVLTreeNode AVLTreeNode
A node in an AVL tree.
Definition avl-tree.h:97
AVLTreeValue * avl_tree_to_array(AVLTree *tree)
Convert the keys in an AVL tree into a C array.
AVLTreeKey avl_tree_node_key(AVLTreeNode *node)
Retrieve the key for a given tree node.
void * AVLTreeValue
A value stored in an AVLTree.
Definition avl-tree.h:79
AVLTreeNode * avl_tree_insert(AVLTree *tree, AVLTreeKey key, AVLTreeValue value)
Insert a new key-value pair into an AVL tree.
int(* AVLTreeCompareFunc)(AVLTreeValue value1, AVLTreeValue value2)
Type of function used to compare keys in an AVL tree.
Definition avl-tree.h:119
struct _AVLTree AVLTree
An AVL tree balanced binary tree.
Definition avl-tree.h:67
void avl_tree_remove_node(AVLTree *tree, AVLTreeNode *node)
Remove a node from a tree.
Definition node.h:24
TChain * tree