Commit 46d7baf4 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 16059f7a
...@@ -385,8 +385,14 @@ def Restructure(ztree, newStructure): ...@@ -385,8 +385,14 @@ def Restructure(ztree, newStructure):
# set znode states according to established tnew->znode association # set znode states according to established tnew->znode association
# bucket.embedded_in_tree will indicate that this bucket's state was
# embedded into containing tree node.
for rb in rbucketv:
rb.node.embedded_in_tree = False
rlevelv = rlevelv_orig rlevelv = rlevelv_orig
for rnodev in rlevelv: for rnodev in reversed(rlevelv):
for rn in rnodev: for rn in rnodev:
node = rn.node node = rn.node
assert isinstance(node, (Tree,Bucket)) assert isinstance(node, (Tree,Bucket))
...@@ -400,10 +406,12 @@ def Restructure(ztree, newStructure): ...@@ -400,10 +406,12 @@ def Restructure(ztree, newStructure):
# empty bucket noone links to # empty bucket noone links to
if len(child.keyv) == 0 and child.prev_bucket is None: if len(child.keyv) == 0 and child.prev_bucket is None:
zstate = None # -> empty tree zstate = None # -> empty tree
child.embedded_in_tree = True
# tree with single bucket noone links to # tree with single bucket noone links to
elif child.Z._p_oid is None and child.prev_bucket is None: elif child.Z._p_oid is None and child.prev_bucket is None:
zstate = ((child.Z.__getstate__(),),) # tree with bucket without oid zstate = ((child.Z.__getstate__(),),) # tree with bucket without oid
child.embedded_in_tree = True
if zstate is unset: if zstate is unset:
# normal tree node # normal tree node
...@@ -415,10 +423,15 @@ def Restructure(ztree, newStructure): ...@@ -415,10 +423,15 @@ def Restructure(ztree, newStructure):
zstate = (zstate,) zstate = (zstate,)
# firstbucket # firstbucket
zstate += (node.firstbucket().Z,) firstbucket = node.firstbucket()
print('firstbucket: %s (embedded: %s)' % (firstbucket, firstbucket.embedded_in_tree))
if not firstbucket.embedded_in_tree:
zstate += (firstbucket.Z,)
# https://github.com/zopefoundation/BTrees/blob/4.5.0-1-gc8bf24e/BTrees/BucketTemplate.c#L1195 # https://github.com/zopefoundation/BTrees/blob/4.5.0-1-gc8bf24e/BTrees/BucketTemplate.c#L1195
if isinstance(node, Bucket): if isinstance(node, Bucket):
# ignore .embedded_in_tree - wrt tree it won't make a
# difference if we change an object not reachable through it.
zstate = () zstate = ()
for k in node.keyv: for k in node.keyv:
zstate += (k, kv.pop(k)) # (k1, v1, k2, v2, ..., kN, vN) zstate += (k, kv.pop(k)) # (k1, v1, k2, v2, ..., kN, vN)
...@@ -434,6 +447,10 @@ def Restructure(ztree, newStructure): ...@@ -434,6 +447,10 @@ def Restructure(ztree, newStructure):
assert tnew.Z is ztree assert tnew.Z is ztree
assert len(kv) == 0 # all keys must have been popped assert len(kv) == 0 # all keys must have been popped
print()
print('new struct:')
print(StructureOf(ztree))
print()
_bcheck(ztree) # verify ztree after our tweaks _bcheck(ztree) # verify ztree after our tweaks
tstruct = StructureOf(ztree) tstruct = StructureOf(ztree)
if tstruct != newStructure: if tstruct != newStructure:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment