1 USING: arrays assocs help.markup help.syntax kernel math ;
5 { $syntax "TREE{ { key value }... }" }
6 { $values { "key" "a key" } { "value" "a value" } }
7 { $description "Literal syntax for an unbalanced tree." } ;
10 { $values { "tree" tree } }
11 { $description "Creates an empty unbalanced binary tree" } ;
14 { $values { "assoc" assoc } { "tree" tree } }
15 { $description "Converts any " { $link assoc } " into an unbalanced binary tree. If the input assoc is any kind of " { $link tree } ", the elements are added in level order (breadth-first search) to copy it's shape." } ;
18 { $class-description "This is the class for unbalanced binary search trees. It is not usually intended to be used directly but rather as a basis for other trees." } ;
25 { $description "Returns the height of " { $snippet "tree" } "." } ;
27 HELP: headtree>alist[)
29 { "to-key" "a key" } { "tree" tree }
30 { "alist" "an array of key/value pairs" }
32 { $description "Returns an alist of the portion of this tree whose keys are strictly less than to-key." } ;
34 HELP: headtree>alist[]
36 { "to-key" "a key" } { "tree" tree }
37 { "alist" "an array of key/value pairs" }
39 { $description "Returns an alist of the portion of this tree whose keys are less than or equal to to-key." } ;
43 { "from-key" "a key" } { "to-key" "a key" } { "tree" tree }
44 { "alist" "an array of key/value pairs" }
46 { $description "Returns an alist of the portion of this map whose keys range from fromKey (exclusive) to toKey (exclusive)." } ;
50 { "from-key" "a key" } { "to-key" "a key" } { "tree" tree }
51 { "alist" "an array of key/value pairs" }
53 { $description "Returns an alist of the portion of this map whose keys range from fromKey (exclusive) to toKey (inclusive)." } ;
57 { "from-key" "a key" } { "to-key" "a key" } { "tree" tree }
58 { "alist" "an array of key/value pairs" }
60 { $description "Returns an alist of the portion of this map whose keys range from fromKey (inclusive) to toKey (exclusive)." } ;
64 { "from-key" "a key" } { "to-key" "a key" } { "tree" tree }
65 { "alist" "an array of key/value pairs" }
67 { $description "Returns an alist of the portion of this map whose keys range from fromKey (inclusive) to toKey (inclusive)." } ;
69 HELP: tailtree>alist(]
71 { "from-key" "a key" } { "tree" tree }
72 { "alist" "an array of key/value pairs" }
74 { $description "Returns an alist of the portion of this tree whose keys are strictly greater than to-key." } ;
76 HELP: tailtree>alist[]
78 { "from-key" "a key" } { "tree" tree }
79 { "alist" "an array of key/value pairs" }
81 { $description "Returns an alist of the portion of this tree whose keys are greater than or equal to to-key." } ;
84 headtree>alist[) headtree>alist[] tailtree>alist(] tailtree>alist[]
85 subtree>alist() subtree>alist(] subtree>alist[) subtree>alist[]
90 { "key" "a key" } { "tree" tree }
91 { "pair/f" { $maybe pair } }
93 { $description "Returns a key-value mapping associated with the least key greater than or equal to the given key, or " { $link f } " if there is no such key." } ;
97 { "key" "a key" } { "tree" tree }
98 { "key/f" { $maybe "a key" } }
100 { $description "Returns the least key greater than or equal to the given key, or " { $link f } " if there is no such key." } ;
104 { "key" "a key" } { "tree" tree }
105 { "pair/f" { $maybe pair } }
107 { $description "Returns a key-value mapping associated with the greatest key less than or equal to the given key, or " { $link f } " if there is no such key." } ;
111 { "key" "a key" } { "tree" tree }
112 { "key/f" { $maybe "a key" } }
114 { $description "Returns the greatest key less than or equal to the given key, or " { $link f } " if there is no such key." } ;
118 { "key" "a key" } { "tree" tree }
119 { "pair/f" { $maybe pair } }
121 { $description "Returns a key-value mapping associated with the least key strictly greater than the given key, or " { $link f } " if there is no such key." } ;
125 { "key" "a key" } { "tree" tree }
126 { "key/f" { $maybe "a key" } }
128 { $description "Returns the least key strictly greater than the given key, or " { $link f } " if there is no such key." } ;
132 { "key" "a key" } { "tree" tree }
133 { "pair/f" { $maybe pair } }
135 { $description "Returns a key-value mapping associated with the greatest key strictly less than the given key, or " { $link f } " if there is no such key." } ;
139 { "key" "a key" } { "tree" tree }
140 { "key/f" { $maybe "a key" } }
142 { $description "Returns the greatest key strictly less than the given key, or " { $link f } " if there is no such key." } ;
144 { lower-key lower-entry higher-key higher-entry
145 floor-key floor-entry ceiling-key ceiling-entry } related-words
150 { "pair/f" { $maybe pair } }
152 { $description "Returns a key-value mapping associated with the last (highest) key in this tree, or " { $link f } " if the tree is empty." } ;
157 { "key/f" { $maybe "a key" } }
159 { $description "Returns the last (highest) key in this tree, or " { $link f } " if the tree is empty." } ;
164 { "pair/f" { $maybe pair } }
166 { $description "Returns a key-value mapping associated with the first (lowest) key in this tree, or " { $link f } " if the tree is empty." } ;
171 { "key/f" { $maybe pair } }
173 { $description "Returns the first (lowest) key in this tree, or " { $link f } " if the tree is empty." } ;
175 { first-key first-entry last-key last-entry } related-words
180 { "node/f" { $maybe pair } }
182 { $description "Removes and returns a key-value mapping associated with the lowest key in this map, or " { $link f } " if the map is empty." } ;
187 { "node/f" { $maybe pair } }
189 { $description "Removes and returns a key-value mapping associated with the highest key in this map, or " { $link f } " if the map is empty." } ;
191 { pop-tree-left pop-tree-right } related-words
193 HELP: slurp-tree-left
195 { "tree" tree } { "quot" { $quotation ( ... entry -- ... ) } }
197 { $description "Removes entries from a tree from the left (lowest key) and processes them with the quotation until the tree is empty." } ;
199 HELP: slurp-tree-right
201 { "tree" tree } { "quot" { $quotation ( ... entry -- ... ) } }
203 { $description "Removes entries from a tree from the right (highest key) and processes them with the quotation until the tree is empty." } ;
205 { slurp-tree-left slurp-tree-right } related-words
207 ARTICLE: "trees" "Binary search trees"
208 "The " { $vocab-link "trees" } " vocabulary is a library for unbalanced binary search trees. A " { $link tree } " is not intended to be used directly in most situations but rather as a base class for new trees, because performance can degrade to linear time storage/retrieval by the number of keys. These binary search trees conform to the assoc protocol."
210 "Constructing trees:"
216 "Operations on trees: "
219 first-entry first-key
222 "Range operations on trees:"
224 headtree>alist[) headtree>alist[] tailtree>alist(] tailtree>alist[]
225 subtree>alist() subtree>alist(] subtree>alist[) subtree>alist[]
227 "Navigation operations on trees:"
229 lower-key lower-entry higher-key higher-entry
230 floor-key floor-entry ceiling-key ceiling-entry
232 "Pop/Slurp operations on trees:"
234 pop-tree-left pop-tree-right
235 slurp-tree-left slurp-tree-right