Commit cc4a3644 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent cdab1972
......@@ -368,50 +368,45 @@ def Restructure(ztree, newStructure):
for rnodev in rlevelv:
for rn in rnodev:
node = rn.node
assert isinstance(node, Tree), node # buckets were filtered out to rbucketv
znode = node.Z
assert isinstance(node, (Tree,Bucket))
# https://github.com/zopefoundation/BTrees/blob/4.5.0-1-gc8bf24e/BTrees/BTreeTemplate.c#L1087
zstate = unset = object()
if len(node.keyv) == 0:
child = node.children[0]
if isinstance(child, Bucket):
# empty bucket noone links to
if len(child.keyv) == 0 and child.prev_bucket is None:
zstate = None # -> empty tree
# tree with single bucket noone links to
elif child.Z._p_oid is None and child.prev_bucket is None:
zstate = ((child.Z.__getstate__(),),) # tree with bucket without oid
if zstate is unset:
# normal tree node
if isinstance(node, Tree):
zstate = unset = object()
if len(node.keyv) == 0:
child = node.children[0]
if isinstance(child, Bucket):
# empty bucket noone links to
if len(child.keyv) == 0 and child.prev_bucket is None:
zstate = None # -> empty tree
# tree with single bucket noone links to
elif child.Z._p_oid is None and child.prev_bucket is None:
zstate = ((child.Z.__getstate__(),),) # tree with bucket without oid
if zstate is unset:
# normal tree node
zstate = ()
assert len(node.children) == len(node.keyv) + 1
zstate += node.children[0]
for (child, k) in zip(node.children[1:], node.keyv):
zstate += (k, child) # (child0, k0, child1, k1, ..., childN, kN, childN+1)
zstate = (zstate,)
# firstbucket
zstate += (None,) # XXX
# https://github.com/zopefoundation/BTrees/blob/4.5.0-1-gc8bf24e/BTrees/BucketTemplate.c#L1195
if isinstance(node, Bucket):
zstate = ()
assert len(node.children) == len(node.keyv) + 1
zstate += node.children[0]
for (child, k) in zip(node.children[1:], node.keyv):
zstate += (k, child) # (child0, k0, child1, k1, ..., childN, kN, childN+1)
for k in node.keyv:
zstate += (k, kv.pop(k)) # (k1, v1, k2, v2, ..., kN, vN)
zstate = (zstate,)
# firstbucket
zstate += (None,) # XXX
znode.__setstate__(zstate)
# ----//---- for buckets
for rbucket in rbucketv:
node = rbucket.node
# https://github.com/zopefoundation/BTrees/blob/4.5.0-1-gc8bf24e/BTrees/BucketTemplate.c#L1195
zstate = ()
for k in node.keyv:
zstate += (k, kv.pop(k)) # (k1, v1, k2, v2, ..., kN, vN)
zstate = (zstate,)
if node.next_bucket is not None: # next
zstate += (node.next_bucket.Z,)
if node.next_bucket is not None: # next
zstate += (node.next_bucket.Z,)
node.Z.__setstate__(zstate)
node.Z.__setstate__(zstate)
assert tnew.Z is ztree
......
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