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
@@ -351,7 +351,7 @@ class Rbyd:
|
||||
if not self:
|
||||
return True, 0, -1, 0, 0, 0, b'', []
|
||||
|
||||
lower = -1
|
||||
lower = 0
|
||||
upper = self.weight
|
||||
path = []
|
||||
|
||||
@@ -366,9 +366,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
|
||||
@@ -401,7 +401,7 @@ class Rbyd:
|
||||
else:
|
||||
rid_ = upper-1
|
||||
tag_ = alt
|
||||
w_ = rid_-lower
|
||||
w_ = upper-lower
|
||||
|
||||
done = not tag_ or (rid_, tag_) < (rid, tag)
|
||||
|
||||
|
||||
+5
-5
@@ -358,7 +358,7 @@ class Rbyd:
|
||||
if not self:
|
||||
return True, 0, -1, 0, 0, 0, b'', []
|
||||
|
||||
lower = -1
|
||||
lower = 0
|
||||
upper = self.weight
|
||||
path = []
|
||||
|
||||
@@ -373,9 +373,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
|
||||
@@ -408,7 +408,7 @@ class Rbyd:
|
||||
else:
|
||||
rid_ = upper-1
|
||||
tag_ = alt
|
||||
w_ = rid_-lower
|
||||
w_ = upper-lower
|
||||
|
||||
done = not tag_ or (rid_, tag_) < (rid, tag)
|
||||
|
||||
|
||||
+5
-5
@@ -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)
|
||||
|
||||
|
||||
+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