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:
+5
-5
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user