Red-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
.
call(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_visit(Tree, Pairs), member(Key-Value, Pairs)
call(Goal, Value)
is true for all nodes in T.call(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.call(Pred, Key-Value, State1, State2)
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.