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
@@ -360,7 +360,7 @@ class Rbyd:
if not self:
return True, 0, -1, 0, 0, 0, b'', []
lower = -1
lower = 0
upper = self.weight
path = []
@@ -375,9 +375,9 @@ class Rbyd:
if ((rid, tag & 0xfff) > (upper-weight_-1, alt & 0xfff)
if alt & TAG_GT
else ((rid, tag & 0xfff)
<= (lower+weight_, alt & 0xfff))):
lower += upper-lower-1-weight_ if alt & TAG_GT else 0
upper -= upper-lower-1-weight_ if not alt & TAG_GT else 0
<= (lower+weight_-1, alt & 0xfff))):
lower += upper-lower-weight_ if alt & TAG_GT else 0
upper -= upper-lower-weight_ if not alt & TAG_GT else 0
j = j - jump
# figure out which color
@@ -410,7 +410,7 @@ class Rbyd:
else:
rid_ = upper-1
tag_ = alt
w_ = rid_-lower
w_ = upper-lower
done = not tag_ or (rid_, tag_) < (rid, tag)