Jan Dvořák <mordae@anilinux.org>
A self-balancing binary search tree variant.
All mutations of the AVL tree create new nodes instead of modifying the data in place. The imperative variants change the root node in place for convenience. Mutating the tree is not thread-safe.
These trees could be used for as priority queues with possibility to remove elements from the middle.
<=?:procedure?procedure
( make-avleq <=?)→avl?
<=?:procedure?procedure
( make-avleqv <=?)→avl?
<=?:procedure?
Like hash tables, every AVL tree variant uses a different equality predicate. make-avl uses equal? , make-avleq uses eq? and make-avleqv uses eqv? .
Tree with number? elements would use <= as the comparator, tree with string? elements would use string<=? and so on.
procedure
( make-custom-avl <=?=?)→avl?
<=?:procedure?=?:procedure?
'((1 . bye) (2 . ciao))
procedure
( avl-equal? v)→boolean?
v:any/c
#f
#t
#f
procedure
( avl-empty? tree)→boolean?
tree:avl?
#f
#t
procedure
( avl-contains? treevalue)→boolean?
tree:avl?value:any/c
#t
#f
procedure
( avl-search treevalue)→any/c?
tree:avl?value:any/c
'((1 . cat) (2 . dog) (3 . mouse))
> (search-by-keyanimal-dict1)'(1 . cat)
> (search-by-keyanimal-dict2)'(2 . dog)
> (search-by-keyanimal-dict3)'(3 . mouse)
> (search-by-keyanimal-dict4)#f
#t
#f
#t
procedure
( avl-remove treevalue)→avl?
tree:avl?value:any/c
#f
#t
procedure
( avl-remove! treevalue)→void?
tree:avl?value:any/c
#f
procedure
( avl-mirror tree)→avl?
tree:avl?
'(99 55 10)
procedure
( avl-mirror! tree)→void?
tree:avl?
procedure
tree:avl?
21
#<avl>
21
procedure
( avl-pop-min! tree)→any/c
tree:avl?
21
42
procedure
tree:avl?
101
#<avl>
101
procedure
( avl-pop-max! tree)→any/c
tree:avl?
101
42
procedure
( in-avl/reverse tree)→sequence?
tree:avl?
'(21/5)