3 mkavltree, insertavl, lookupavl, deleteavl, avlwalk, avlnext, avlprev, endwalk - AVL tree routines
5 .\" .ta 0.75i 1.5i 2.25i 3i 3.75i 4.5i
6 .ta 0.7i +0.7i +0.7i +0.7i +0.7i +0.7i +0.7i
12 typedef struct Avl Avl;
16 Avl *n[2]; /* children */
17 int bal; /* balance bits */
20 Avl *avlnext(Avlwalk *walk);
21 Avl *avlprev(Avlwalk *walk);
22 Avlwalk *avlwalk(Avltree *tree);
23 void deleteavl(Avltree *tree, Avl *key, Avl **oldp);
24 void endwalk(Avlwalk *walk);
25 void insertavl(Avltree *tree, Avl *new, Avl **oldp);
26 Avl *lookupavl(Avltree *tree, Avl *key);
27 Avltree *mkavltree(int(*cmp)(Avl*, Avl*));
30 An AVL tree is a self-balancing binary search tree.
31 These routines allow creation and maintenance of in-memory AVL trees.
33 An empty AVL tree is created by calling
35 with a comparison function as argument.
36 This function should take two pointers to
38 objects and return -1, 0 or 1 as the first is
39 respectively less than,
40 equal to, or greater than,
49 is non-nil upon return,
50 it points to storage for an old node
51 with the same key that may now be freed.
64 removes the node matching
73 returns a pointer to a newly-allocated
81 walk the tree associated with
84 (respectively, previous)
85 tree node in the comparison order
86 defined by the comparison function
87 associated with the tree associated with
90 Intended usage seems to be to make an anonymous
92 the first member of the application's tree-node structure,
93 then pass these routines tree-node pointers instead of
99 uchar score[VtScoreSize];
107 res = lookupavl(tree, np);
112 G. M. Adelson-Velsky,
114 ``An algorithm for the organization of information'',
115 .IR "Soviet Mathematics" ,
116 Vol. 3, pp. 1256—1263.
118 Functions returning pointers return