Commit ef6fb8db authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 38dacb30
......@@ -89,7 +89,7 @@ better:
from __future__ import print_function, absolute_import
from BTrees import check as zbcheck
from golang import func, panic
from golang import func, panic, defer
from golang.gcompat import qq
import itertools
import re
......@@ -216,12 +216,30 @@ def StructureOf(znode):
# topology structure.
#
# NOTE ZODB BTree package does not tolerate structures with empty BTree nodes
# except for the single case of empty tree.
# except for the sole single case of empty tree.
@func
def Restructure(ztree, newStructure):
_ = _zclassify(ztree)
assert _.is_ztree
assert isinstance(newStructure, Tree)
#print('\nRestructure %s ->\n%s' % (ztree, newStructure))
from_ = TopoEncode(StructureOf(ztree))
to_ = TopoEncode(newStructure)
"""
def _():
exc = recover() # FIXME for panic - returns unwrapped arg, not PanicError
if exc is not None:
# FIXME %w creates only .Unwrap link, not with .__cause__ -> fix
raise fmt.Errorf("Restructure %s -> %s: %w", from_, to_, exc)
defer(_)
"""
def _(): # XXX hack
exc = sys.exc_info()[1]
if exc is not None:
assert len(exc.args) == 1
exc.args = ("Restructure %s -> %s: %r" % (from_, to_, exc.args[0]),)
defer(_)
ztreeType = type(ztree)
zbucketType = ztreeType._bucket_type
......@@ -244,7 +262,7 @@ def Restructure(ztree, newStructure):
# - find solution to linear assignment problem A <- B with the cost given by D
# https://en.wikipedia.org/wiki/Assignment_problem
#
# D(A,B) = |A.lo, B.lo| + |A.hi - B.hi|
# D(A,B) = |A.lo - B.lo| + |A.hi - B.hi|
# we will modify nodes from new set:
# - node.Z will point to associated znode
......@@ -312,8 +330,7 @@ def Restructure(ztree, newStructure):
# assert the result is 1-1 mapping
for j in range(len(RNv)):
if RNv[j].node.Z is not RZv[j].node:
panic("BUG: Restructure %s -> %s: assign: not 1-1 mapping:\n RZv: %s\nRNv: %s" %
(TopoEncode(StructureOf(ztree)), TopoEncode(newStructure), RZv, RNv))
panic("BUG: assign: not 1-1 mapping:\n RZv: %s\nRNv: %s" % (RZv, RNv))
# XXX assert assignments are in key↑ order ?
......
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