forked from Imagelibrary/littlefs
Changed source to consistently use rid for rbyd ids
Originally it made sense to name the rbyd ids, well, ids, at least in the internals of the rbyd functions. But this doesn't work well outside of the rbyd code, where littlefs has to juggle several different id types with different purposes: - rid => rbyd-id, 31-bit index into an rbyd - bid => btree-id, 31-bit index into a btree - mid => mdir-id, 15-bit+15-bit index into the mtree - did => directory-id, 31-bit unique identifier for directories Even though context makes it clear which id the id refers to in the rbyd internals, updating the name to rid makes it clearer that these are the same type of id when looking at code both inside and outside the rbyd functions.
This commit is contained in:
@@ -318,7 +318,7 @@ class Rbyd:
|
||||
|
||||
return cls(block, data, rev, off, trunk_, weight)
|
||||
|
||||
def lookup(self, id, tag):
|
||||
def lookup(self, rid, tag):
|
||||
if not self:
|
||||
return True, 0, -1, 0, 0, 0, b'', []
|
||||
|
||||
@@ -334,9 +334,9 @@ class Rbyd:
|
||||
# found an alt?
|
||||
if alt & 0x4000:
|
||||
# follow?
|
||||
if ((id, tag & 0xfff) > (upper-weight_-1, alt & 0xfff)
|
||||
if ((rid, tag & 0xfff) > (upper-weight_-1, alt & 0xfff)
|
||||
if alt & 0x2000
|
||||
else ((id, tag & 0xfff)
|
||||
else ((rid, tag & 0xfff)
|
||||
<= (lower+weight_, alt & 0xfff))):
|
||||
lower += upper-lower-1-weight_ if alt & 0x2000 else 0
|
||||
upper -= upper-lower-1-weight_ if not alt & 0x2000 else 0
|
||||
@@ -370,13 +370,13 @@ class Rbyd:
|
||||
|
||||
# found tag
|
||||
else:
|
||||
id_ = upper-1
|
||||
rid_ = upper-1
|
||||
tag_ = alt
|
||||
w_ = id_-lower
|
||||
w_ = rid_-lower
|
||||
|
||||
done = not tag_ or (id_, tag_) < (id, tag)
|
||||
done = not tag_ or (rid_, tag_) < (rid, tag)
|
||||
|
||||
return done, id_, tag_, w_, j, d, self.data[j+d:j+d+jump], path
|
||||
return done, rid_, tag_, w_, j, d, self.data[j+d:j+d+jump], path
|
||||
|
||||
def __bool__(self):
|
||||
return bool(self.trunk)
|
||||
@@ -389,29 +389,29 @@ class Rbyd:
|
||||
|
||||
def __iter__(self):
|
||||
tag = 0
|
||||
id = -1
|
||||
rid = -1
|
||||
|
||||
while True:
|
||||
done, id, tag, w, j, d, data, _ = self.lookup(id, tag+0x1)
|
||||
done, rid, tag, w, j, d, data, _ = self.lookup(rid, tag+0x1)
|
||||
if done:
|
||||
break
|
||||
|
||||
yield id, tag, w, j, d, data
|
||||
yield rid, tag, w, j, d, data
|
||||
|
||||
# create tree representation for debugging
|
||||
def tree(self):
|
||||
trunks = co.defaultdict(lambda: (-1, 0))
|
||||
alts = co.defaultdict(lambda: {})
|
||||
|
||||
id, tag = -1, 0
|
||||
rid, tag = -1, 0
|
||||
while True:
|
||||
done, id, tag, w, j, d, data, path = self.lookup(id, tag+0x1)
|
||||
done, rid, tag, w, j, d, data, path = self.lookup(rid, tag+0x1)
|
||||
# found end of tree?
|
||||
if done:
|
||||
break
|
||||
|
||||
# keep track of trunks/alts
|
||||
trunks[j] = (id, tag)
|
||||
trunks[j] = (rid, tag)
|
||||
|
||||
for j_, j__, followed, c in path:
|
||||
if followed:
|
||||
|
||||
Reference in New Issue
Block a user