kopia lustrzana https://github.com/snarfed/bridgy-fed
Bluesky MST: fixed trivial tree test!
rodzic
96c6f9808f
commit
52a479b8c4
|
@ -56,6 +56,7 @@ import dag_cbor.encoding
|
||||||
from multiformats import CID, multicodec, multihash
|
from multiformats import CID, multicodec, multihash
|
||||||
|
|
||||||
|
|
||||||
|
# this is treeEntry in mst.ts
|
||||||
Entry = namedtuple('Entry', [
|
Entry = namedtuple('Entry', [
|
||||||
'p', # int, length of prefix that this key shares with the prev key
|
'p', # int, length of prefix that this key shares with the prev key
|
||||||
'k', # bytes, the rest of the key outside the shared prefix
|
'k', # bytes, the rest of the key outside the shared prefix
|
||||||
|
@ -128,7 +129,7 @@ class MST:
|
||||||
:class:`MST`
|
:class:`MST`
|
||||||
"""
|
"""
|
||||||
mst = MST(entries=entries, pointer=self.pointer, layer=self.layer)
|
mst = MST(entries=entries, pointer=self.pointer, layer=self.layer)
|
||||||
mst.outdatedPointer = True
|
mst.outdated_pointer = True
|
||||||
return mst
|
return mst
|
||||||
|
|
||||||
|
|
||||||
|
@ -248,7 +249,7 @@ class MST:
|
||||||
new_sub_tree = sub_tree.add(key, value, key_zeros)
|
new_sub_tree = sub_tree.add(key, value, key_zeros)
|
||||||
return self.splice_in(new_sub_tree, index)
|
return self.splice_in(new_sub_tree, index)
|
||||||
|
|
||||||
else:
|
else: # key_zeros > layer
|
||||||
# it belongs on a higher layer, push the rest of the tree down
|
# it belongs on a higher layer, push the rest of the tree down
|
||||||
left, right = self.split_around(key)
|
left, right = self.split_around(key)
|
||||||
# if the newly added key has >=2 more leading zeros than the current
|
# if the newly added key has >=2 more leading zeros than the current
|
||||||
|
@ -903,23 +904,25 @@ def serialize_node_data(entries):
|
||||||
last_key = ''
|
last_key = ''
|
||||||
while i < len(entries):
|
while i < len(entries):
|
||||||
leaf = entries[i]
|
leaf = entries[i]
|
||||||
|
next = entries[i + 1] if i < len(entries) - 1 else None
|
||||||
|
|
||||||
if not isinstance(leaf, Leaf):
|
if not isinstance(leaf, Leaf):
|
||||||
raise ValueError('Not a valid node: two subtrees next to each other')
|
raise ValueError('Not a valid node: two subtrees next to each other')
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
subtree = None
|
subtree = None
|
||||||
if i < len(entries) - 1 and isinstance(entries[i + 1], MST):
|
if next and isinstance(next, MST):
|
||||||
subtree = entries[i + 1].pointer
|
subtree = next.pointer
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
ensure_valid_key(leaf.key)
|
ensure_valid_key(leaf.key)
|
||||||
prefix_len = common_prefix_len(last_key, leaf.key)
|
prefix_len = common_prefix_len(last_key, leaf.key)
|
||||||
data.e.append({
|
data.e.append(Entry(
|
||||||
'p': prefix_len,
|
p=prefix_len,
|
||||||
'k': leaf.key[prefix_len:],
|
k=leaf.key[prefix_len:].encode('ascii'),
|
||||||
'v': leaf.value,
|
v=leaf.value,
|
||||||
't': subtree,
|
t=subtree,
|
||||||
})
|
)._asdict())
|
||||||
|
|
||||||
last_key = leaf.key
|
last_key = leaf.key
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue