Reversed LFSR_ATTR id/tag argument order

I've been wanting to make this change for a while now (tag,id => id,tag).
The id,tag order matches the common lexicographic order used for sorting
tuples. Sorting tag,id tuples by their id first is less common.

The reason for this order in the codebase is because all attrs on disk
start with their tag first, since its decoding determines the purpose of
the id field (keep in mind this includes other non-tree tags such as
crcs, alts, etc). But with the move to storing weights instead of tags
on disk, this gives us a clear point to switch from tag,w to id,tag
ordering.

I may be thinking to much about this, but it does affect a significant
amount of the codebase.
This commit is contained in:
Christopher Haster
2023-04-07 13:03:03 -05:00
parent a463d6f106
commit 7eb0c4763a
5 changed files with 2534 additions and 2535 deletions
+9 -9
View File
@@ -199,7 +199,7 @@ class Rbyd:
return Rbyd(block, limit, data, rev, off, trunk, weight)
def lookup(self, tag, id):
def lookup(self, id, tag):
if not self:
return True, 0, -1, 0, 0, 0, b''
@@ -227,13 +227,13 @@ class Rbyd:
j = j + delta
# found tag
else:
tag_ = alt
id_ = upper-1
tag_ = alt
w_ = id_-lower
done = (id_, tag_) < (id, tag) or tag_ & 2
return (done, tag_, id_, w_,
return (done, id_, tag_, w_,
j, delta, self.data[j+delta:j+delta+jump])
def __bool__(self):
@@ -250,11 +250,11 @@ class Rbyd:
id = 0
while True:
done, tag, id, w, j, d, data = self.lookup(tag+0x10, id)
done, id, tag, w, j, d, data = self.lookup(id, tag+0x10)
if done:
break
yield tag, id, w, j, d, data
yield id, tag, w, j, d, data
def main(disk, block_size=None, trunk=0, limit=None, *,
@@ -306,8 +306,8 @@ def main(disk, block_size=None, trunk=0, limit=None, *,
while True:
# first lookup id/name
(done, name_tag, rid_, w,
name_j, name_d, name) = rbyd.lookup(0, rid)
(done, rid_, name_tag, w,
name_j, name_d, name) = rbyd.lookup(rid, 0)
if done:
return (True, id, 0, rbyd, -1,
(0, 0, 0, b''),
@@ -316,9 +316,9 @@ def main(disk, block_size=None, trunk=0, limit=None, *,
if name_tag & 0xf00f == TAG_NAME:
# then lookup struct
(done, struct_tag, _, _,
(done, _, struct_tag, _,
struct_j, struct_d, struct_) = rbyd.lookup(
TAG_STRUCT, rid_)
rid_, TAG_STRUCT)
if done:
return (True, id, 0, rbyd, -1,
(0, 0, 0, b''),
+7 -7
View File
@@ -493,7 +493,7 @@ def show_tree(block_size, data, rev, trunk, weight, *,
# lookup a tag, returning also the search path for decoration
# purposes
def lookup(tag, id):
def lookup(id, tag):
lower = -1
upper = weight
path = []
@@ -541,13 +541,13 @@ def show_tree(block_size, data, rev, trunk, weight, *,
path.append((j-delta, j, False, 'b'))
# found tag
else:
tag_ = alt
id_ = upper-1
tag_ = alt
w_ = id_-lower
done = (id_, tag_) < (id, tag) or tag_ & 2
return done, tag_, id_, w_, j, delta, jump, path
return done, id_, tag_, w_, j, delta, jump, path
# precompute tree
tree_width = 0
@@ -555,9 +555,9 @@ def show_tree(block_size, data, rev, trunk, weight, *,
trunks = co.defaultdict(lambda: (-1, 0))
alts = co.defaultdict(lambda: {})
tag, id = 0, -1
id, tag = -1, 0
while True:
done, tag, id, w, j, delta, size, path = lookup(tag+0x10, id)
done, id, tag, w, j, delta, size, path = lookup(id, tag+0x10)
# found end of tree?
if done:
break
@@ -690,9 +690,9 @@ def show_tree(block_size, data, rev, trunk, weight, *,
'data (truncated)'
if not args.get('no_truncate') else ''))
tag, id = 0, -1
id, tag = -1, 0
while True:
done, tag, id, w, j, delta, size, path = lookup(tag+0x10, id)
done, id, tag, w, j, delta, size, path = lookup(id, tag+0x10)
# found end of tree?
if done:
break