Skip to content

Commit

Permalink
fix _put_recursive tree grow case
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBuchanan314 committed Oct 21, 2024
1 parent 13d794f commit 8138bde
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/atmst/mst/node_wrangler.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ def _put_here(self, node: MSTNode, key: str, val: CID) -> MSTNode:
def _put_recursive(self, node: MSTNode, key: str, val: CID, key_height: int, tree_height: int) -> MSTNode:
if key_height > tree_height: # we need to grow the tree
return self.ns.stored_node(self._put_recursive(
MSTNode.empty_root(),
self.ns.stored_node(MSTNode(
keys=(),
vals=(),
subtrees=(node.cid,)
)),
key, val, key_height, tree_height + 1
))

Expand Down
13 changes: 13 additions & 0 deletions tests/test_mst_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
from atmst.mst.node import MSTNode
from cbrrr import CID

def dump_mst(ns: NodeStore, cid: CID, lvl=0):
node = ns.get_node(cid)
print(" "*lvl + "-", node)
for subtree in node.subtrees:
if subtree:
dump_mst(ns, subtree, lvl+1)

class MSTDiffTestCase(unittest.TestCase):
def setUp(self):
keys = []
Expand Down Expand Up @@ -60,6 +67,12 @@ def test_insertion_order_independent(self):
for k in keys:
mst_c = wrangler.put_record(mst_c, k, CID.cidv1_dag_cbor_sha256_32_from(k.encode()))

#print()
#dump_mst(self.ns, mst_a)

#print()
#dump_mst(self.ns, mst_b)

self.assertEqual(mst_a, mst_b)
self.assertEqual(mst_a, mst_c)

Expand Down

0 comments on commit 8138bde

Please sign in to comment.