
rbtrees.pl -- Red black treesRed-Black trees are balanced search binary trees. They are named because nodes can be classified as either red or black. The code we include is based on "Introduction to Algorithms", second edition, by Cormen, Leiserson, Rivest and Stein. The library includes routines to insert, lookup and delete elements in the tree.
A Red black tree is represented as a term t(Nil, Tree), where Nil is the
Nil-node, a node shared for each nil-node in the tree. Any node has the
form colour(Left, Key, Value, Right), where colour is one of red or
black.
rb_new(-Tree) is det
rb_empty(?Tree) is semidet
rb_lookup(+Key, -Value, +Tree) is semidet
rb_min(+Tree, -Key, -Value) is semidet
rb_max(+Tree, -Key, -Value) is semidet
rb_next(+Tree, +Key, -Next, -Value) is semidet
rb_previous(+Tree, +Key, -Previous, -Value) is semidet
rb_update(+Tree, +Key, +NewVal, -NewTree) is semidet
rb_update(+Tree, +Key, ?OldVal, +NewVal, -NewTree) is semidet
rb_apply(+Tree, +Key, :G, -NewTree) is semidetcall(G,Val0,ValF) holds, then NewTree differs from Tree only in that
Key is associated with value ValF in tree NewTree. Fails if it
cannot find Key in Tree, or if call(G,Val0,ValF) is not satisfiable.
rb_in(?Key, ?Value, +Tree) is nondetrb_visit(Tree, Pairs), member(Key-Value, Pairs)
rb_insert(+Tree, +Key, ?Value, -NewTree) is det
rb_insert_new(+Tree, +Key, ?Value, -NewTree) is semidet
rb_delete(+Tree, +Key, -NewTree)
rb_delete(+Tree, +Key, -Val, -NewTree)
rb_del_min(+Tree, -Key, -Val, -NewTree)
rb_del_max(+Tree, -Key, -Val, -NewTree)
rb_visit(+Tree, -Pairs)
rb_map(+T, :Goal) is semidetcall(Goal, Value) is true for all nodes in T.
rb_map(+Tree, :G, -NewTree) is semidetcall(G,Val0,ValF) holds, then the
value associated with Key in NewTree is ValF. Fails if
call(G,Val0,ValF) is not satisfiable for all Val0.
rb_fold(:Goal, +Tree, +State0, -State) is detcall(Pred, Key-Value, State1, State2)
rb_clone(+TreeIn, -TreeOut, -Pairs) is det
rb_partial_map(+Tree, +Keys, :G, -NewTree)call(G,Val0,ValF) holds, then the value
associated with Key in NewTree is ValF. Fails if or if
call(G,Val0,ValF) is not satisfiable for all Val0. Assumes keys are
not repeated.
rb_keys(+Tree, -Keys)
list_to_rbtree(+List, -Tree) is det
ord_list_to_rbtree(+List, -Tree) is det
rb_size(+Tree, -Size) is det
is_rbtree(@Term) is semidet
rb_update(+Tree, +Key, +NewVal, -NewTree) is semidet
rb_update(+Tree, +Key, ?OldVal, +NewVal, -NewTree) is semidet
rb_delete(+Tree, +Key, -NewTree)
rb_delete(+Tree, +Key, -Val, -NewTree)