Tweaked rbyd lookup/append to use 0 lower rid bias

Previously our lower/upper bounds were initialized to -1..weight. This
made a lot of the math unintuitive and confusing, and it's not really
necessary to support -1 rids (-1 rids arise naturally in order-statistic
trees the can have weight=0).

The tweak here is to use lower/upper bounds initialized to 0..weight,
which makes the math behave as expected. -1 rids naturally arise from
rid = upper-1.
This commit is contained in:
Christopher Haster
2023-10-01 14:31:54 -05:00
parent 501f8cbe10
commit ef691d4cfe
5 changed files with 35 additions and 35 deletions
+5 -5
View File
@@ -602,7 +602,7 @@ def dbg_tree(data, block_size, rev, trunk, weight, *,
# lookup a tag, returning also the search path for decoration
# purposes
def lookup(rid, tag):
lower = -1
lower = 0
upper = weight
path = []
@@ -616,9 +616,9 @@ def dbg_tree(data, block_size, rev, trunk, weight, *,
# follow?
if ((rid, tag & 0xfff) > (upper-w-1, alt & 0xfff)
if alt & TAG_GT
else ((rid, tag & 0xfff) <= (lower+w, alt & 0xfff))):
lower += upper-lower-1-w if alt & TAG_GT else 0
upper -= upper-lower-1-w if not alt & TAG_GT else 0
else ((rid, tag & 0xfff) <= (lower+w-1, alt & 0xfff))):
lower += upper-lower-w if alt & TAG_GT else 0
upper -= upper-lower-w if not alt & TAG_GT else 0
j = j - jump
# figure out which color
@@ -651,7 +651,7 @@ def dbg_tree(data, block_size, rev, trunk, weight, *,
else:
rid_ = upper-1
tag_ = alt
w_ = rid_-lower
w_ = upper-lower
done = not tag_ or (rid_, tag_) < (rid, tag)