forked from skaphan/stmmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAVLtree.h
58 lines (43 loc) · 1.75 KB
/
AVLtree.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
AVLtree.h
Interface to implementation of AVL trees, a form of balanced binary trees.
This is a low level implementation which does not depend on anything else
in stmmap in any way.
Copyright 2009 Shel Kaphan
This file is part of stmmap.
stmmap is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
stmmap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with stmmap. If not, see <http://www.gnu.org/licenses/>.
*/
typedef struct AVLtreeNode
{
struct AVLtreeNode* parent;
struct AVLtreeNode* left;
struct AVLtreeNode* right;
int depth;
} AVLtreeNode;
/*
Add a node "i" to the tree "*tree". The tree is rebalanced, and possibly
re-rooted after the insertion (that's why the pointer-to-pointer is passed).
*/
void AVLaddToTree(AVLtreeNode* i, AVLtreeNode** tree, int (*cmp)(void*,void*), void*(*getKey)(void*));
/*
Removes a node "t" from a tree.
*/
void AVLremoveFromTree(AVLtreeNode* t, AVLtreeNode** tree);
/*
Search for a node in the tree using a user supplied comparison function, and key extractor.
*/
AVLtreeNode* AVLsearch(AVLtreeNode* t, void* key, int (*cmp)(void*,void*), void* (*getKey)(void*));
/*
For "subtypes" of AVLtreeNode, there's a hook which, if set, is called on each node when the
node's depth is being calculated.
*/
extern void (*AVLuserHook)(AVLtreeNode*);