DanielStutzbach / blist

A list-like type with better asymptotic performance and similar performance on small lists
Other
310 stars 36 forks source link

Replace "leaf" with "height" #8

Open DanielStutzbach opened 14 years ago

DanielStutzbach commented 14 years ago

Height == 0 indicates a leaf Height == 1 indicates the parent of a leaf etc.

"height" uses the same memory footprint as "leaf" and requires the same number of CPU instructions to test for leafiness.

"height" will speed up a few operations slightly. Specifically, the extend operation would become O(|log n - log k|), an improvement over O(log n + log k). Many other operations internally use "extend" and would get a small constant-factor speedup.

Finally, "height" will allow for additional error-checking in debug builds, since we can check the following invariant: the height of any non-leaf node's children must equal the node's height minus one.