4 Splay Trees
(require data/splay-tree) | package: data-lib |
Splay trees are an efficient data structure for mutable dictionaries with totally ordered keys. They were described in the paper “Self-Adjusting Binary Search Trees” by Daniel Sleator and Robert Tarjan in Journal of the ACM 32(3) pp652-686.
A splay-tree is a ordered dictionary (dict? and ordered-dict?).
Operations on splay-trees are not thread-safe. If a key in a splay-tree is mutated, the splay-tree’s internal invariants may be violated, causing its behavior to become unpredictable.
procedure
(make-splay-tree [ ord #:key-contract key-contract #:value-contract value-contract]) → splay-tree? ord : order? = datum-order key-contract : contract? = any/c value-contract : contract? = any/c
Examples: | ||||||||||||||||||||||||||||||||||
|
procedure
(make-adjustable-splay-tree [ #:key-contract key-contract #:value-contract value-contract]) → splay-tree? key-contract : contract? = any/c value-contract : contract? = any/c
Examples: | ||||||||||||||||||
|
procedure
(splay-tree? x) → boolean?
x : any/c
procedure
x : any/c
procedure
(splay-tree-ref s key [default]) → any
s : splay-tree? key : any/c default : any/c = (lambda () (error ....))
procedure
(splay-tree-set! s key value) → void?
s : splay-tree? key : any/c value : any/c
procedure
(splay-tree-remove! s key) → void?
s : splay-tree? key : any/c
procedure
s : splay-tree?
procedure
(splay-tree-iterate-first s) → (or/c #f splay-tree-iter?)
s : splay-tree?
procedure
(splay-tree-iterate-next s iter) → (or/c #f splay-tree-iter?)
s : splay-tree? iter : splay-tree-iter?
procedure
(splay-tree-iterate-key s iter) → any/c
s : splay-tree? iter : splay-tree-iter?
procedure
(splay-tree-iterate-value s iter) → any/c
s : splay-tree? iter : splay-tree-iter?
procedure
(splay-tree-remove-range! s from to) → void?
s : splay-tree? from : any/c to : any/c
This operation takes O(N) time, or O(log N) time if (adjustable-splay-tree? s).
procedure
(splay-tree-contract! s from to) → void?
s : adjustable-splay-tree? from : exact-integer? to : exact-integer?
This operation is only allowed on adjustable splay trees, and it takes O(log N) time.
procedure
(splay-tree-expand! s from to) → void?
s : adjustable-splay-tree? from : exact-integer? to : exact-integer?
This operation is only allowed on adjustable splay trees, and it takes O(log N) time.
procedure
(splay-tree-iterate-least s) → (or/c #f splay-tree-iter?)
s : splay-tree
procedure
(splay-tree-iterate-greatest s) → (or/c #f splay-tree-iter?)
s : splay-tree
procedure
(splay-tree-iterate-least/>? s key) → (or/c #f splay-tree-iter?)
s : splay-tree? key : any/c
procedure
(splay-tree-iterate-least/>=? s key)
→ (or/c #f splay-tree-iter?) s : splay-tree? key : any/c
procedure
(splay-tree-iterate-greatest/<? s key)
→ (or/c #f splay-tree-iter?) s : splay-tree? key : any/c
procedure
(splay-tree-iterate-greatest/<=? s key)
→ (or/c #f splay-tree-iter?) s : splay-tree? key : any/c
procedure
(splay-tree-iter? x) → boolean?
x : any/c
procedure
(splay-tree->list s) → (listof pair?)
s : splay-tree?