Commit 46509a57 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent d2172906
......@@ -259,8 +259,10 @@ def Restructure(ztree, newStructure):
assert _.is_ztree
assert isinstance(newStructure, Tree)
newStructOnlyKeys = newStructure.copy(onlyKeys=True)
from_ = TopoEncode(StructureOf(ztree, onlyKeys=True))
to_ = TopoEncode(newStructure)
to_ = TopoEncode(newStructOnlyKeys)
"""
def _():
exc = recover() # FIXME for panic - returns unwrapped arg, not PanicError
......@@ -304,7 +306,7 @@ def Restructure(ztree, newStructure):
# we will modify nodes from new set:
# - node.Z will point to associated znode
# - bucket.next_bucket will point to bucket that is coming with next keys in the tree
tnew = newStructure.copy()
tnew = newStructure.copy() # NOTE _with_ values
# assign assigns tree nodes from RNv to ztree nodes from RZv in optimal way.
# Bj ∈ RNv is mapped into Ai ∈ RZv such that that sum_j D(A_i, Bj) is minimal.
......@@ -520,9 +522,9 @@ def Restructure(ztree, newStructure):
_zbcheck(ztree) # verify ztree after our tweaks
tstruct = StructureOf(ztree, onlyKeys=True)
if tstruct != newStructure:
if tstruct != newStructOnlyKeys:
panic("BUG: result structure is not what was"
" requested:\n%s\n\nwant:\n%s" % (tstruct, newStructure))
" requested:\n%s\n\nwant:\n%s" % (tstruct, newStructOnlyKeys))
# AllStructs generates subset of all possible BTree structures for BTrees with
......
......@@ -482,7 +482,8 @@ def test_restructure():
newStructure = newtopo
xbtree.Restructure(ztree, newStructure)
assert xbtree.StructureOf(ztree, onlyKeys=True) == newStructure
assert xbtree.StructureOf(ztree, onlyKeys=True) == \
newStructure.copy(onlyKeys=True)
# verify iteration producess the same [] of (key, v)
assert list(ztree.items()) == items
......@@ -677,6 +678,18 @@ def test_restructure():
assertB(b8, 8)
# ---- new strucure given with values ----
z = Z(0,2)
R(z, T([1], Bv([0],X[0]), Bv([2],X[2])))
b0, b2 = assertT(z, [1], 'B','B')
assertB(b0, 0)
assertB(b2, 2)
assert b0[0] is X[0]
assert b2[2] is X[2]
# XXX raises if k->v different
# ---- tricky cases
z = Z(0,1,2,3)
......
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