Commit 2e1fb4d8 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent c4a7a252
......@@ -221,13 +221,12 @@ def Restructure(ztree, newStructure):
_ = _zclassify(ztree)
assert _.is_ztree
assert isinstance(newStructure, Tree)
print('\nRestructure %s ->\n%s' % (ztree, newStructure))
#print('\nRestructure %s ->\n%s' % (ztree, newStructure))
ztreeType = type(ztree)
zbucketType = ztreeType._bucket_type
_zbcheck(ztree) # verify ztree before our tweaks
print()
# dict with all k->v from ztree
kv = dict(ztree)
......@@ -300,13 +299,7 @@ def Restructure(ztree, newStructure):
# assignments more efficiently taking into account that Av and Bv are
# key↑ and the property of D function so that if B2 > B1 (all keys in
# B2 > all keys in B1) and A < B1.hi, then D(B2, A) > D(B1, A).
"""
print()
print('COST:')
print(C)
"""
jv, iv = scipy.optimize.linear_sum_assignment(C)
#print(jv, iv)
for (j,i) in zip(jv, iv):
RNv[j].node.Z = RZv[i].node
......@@ -315,7 +308,6 @@ def Restructure(ztree, newStructure):
# to newly created Z nodes.
for j2 in range(len(RNv)):
if j2 not in jv:
#print('\n\n\nXXX create new @%d\n\n\n' % j2)
n = RNv[j2].node
assert n.Z is None
assert isinstance(n, (Tree,Bucket))
......@@ -443,7 +435,7 @@ def Restructure(ztree, newStructure):
zstate = (zstate,)
# firstbucket
print(' (firstbucket -> B %x)' % (id(node.firstbucket().Z),))
#print(' (firstbucket -> B %x)' % (id(node.firstbucket().Z),))
zstate += (node.firstbucket().Z,)
# https://github.com/zopefoundation/BTrees/blob/4.5.0-1-gc8bf24e/BTrees/BucketTemplate.c#L1195
......@@ -455,9 +447,8 @@ def Restructure(ztree, newStructure):
if node.next_bucket is not None: # next
zstate += (node.next_bucket.Z,)
print('B %x -> %x' % (id(node.Z), id(node.next_bucket.Z)))
print('%s %x: ZSTATE: %r' % ('T' if _zclassify(node.Z).is_ztree else 'B', id(node.Z), zstate,))
#print('%s %x: ZSTATE: %r' % ('T' if _zclassify(node.Z).is_ztree else 'B', id(node.Z), zstate,))
node.Z.__setstate__(zstate)
zstate2 = node.Z.__getstate__()
if zstate2 != zstate:
......@@ -469,10 +460,6 @@ def Restructure(ztree, newStructure):
assert tnew.Z is ztree
assert len(kv) == 0 # all keys must have been popped
print()
print('new struct:')
print(StructureOf(ztree))
print()
_zbcheck(ztree) # verify ztree after our tweaks
tstruct = StructureOf(ztree)
if tstruct != newStructure:
......
......@@ -494,7 +494,7 @@ def test_restructure():
assert crack_btree(z) == (BTREE_EMPTY, [], [])
return z
# ---- tests ----
# ---- tests with manual verification of resulting topology and nodes ----
# ø -> T/B
z = Z0()
......@@ -671,9 +671,13 @@ def test_restructure():
assertB(b8, 8)
# ---- tests on automatically generated topologies ----
#
# ( we make sure that Restructure can make the restructurement and that
# after restructure a tree remains valid without any error introduced )
#for nkeys in range(5):
# pass
for nkeys in range(5): # XXX
pass
def test_walkBFS():
......
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