Commit 80f0e5eb authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 87bcad49
......@@ -177,7 +177,7 @@ class Tree(object):
class Bucket(object):
# .keyv () of keys
# .valuev None | () of values len(.valuev) == len(.keyv)
def __init__(b, keyv, valuev): # XXX syntax sugar for values? (lack of values)?
def __init__(b, keyv, valuev):
_assertIncv(keyv)
b.keyv = tuple(keyv)
if valuev is None:
......@@ -249,7 +249,7 @@ def StructureOf(znode, onlyKeys=False):
# Restructure reorganizes ZODB BTree instance (not Tree) according to specified
# topology structure.
#
# The new structure should be given with buckets without values. XXX should -> can?
# The new structure should be given with key-only buckets.
#
# NOTE ZODB BTree package does not tolerate structures with empty BTree nodes
# except for the sole single case of empty tree.
......@@ -265,7 +265,7 @@ def Restructure(ztree, 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
# FIXME %w creates only .Unwrap link, not with .__cause__
raise fmt.Errorf("Restructure %s -> %s: %w", from_, to_, exc)
defer(_)
"""
......@@ -304,7 +304,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() # XXX onlyKeys=True ?
tnew = newStructure.copy()
# 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.
......@@ -490,7 +490,14 @@ def Restructure(ztree, newStructure):
# https://github.com/zopefoundation/BTrees/blob/4.5.0-1-gc8bf24e/BTrees/BucketTemplate.c#L1195
if isinstance(node, Bucket):
# XXX assert that node.values is None or == kv[k] for k in node
# if Bucket was specified with values - verify k->v do not
# change from what was in original tree.
if node.valuev is not None:
assert len(node.keyv) == len(node.valuev)
for (k,v) in zip(node.keyv, node.valuev):
if kv[k] is not v:
raise ValueError("target bucket changes [%d] %r -> %r", k, kv[k], v)
zstate = ()
for k in node.keyv:
zstate += (k, kv.pop(k)) # (k1, v1, k2, v2, ..., kN, vN)
......@@ -503,7 +510,7 @@ def Restructure(ztree, newStructure):
node.Z.__setstate__(zstate)
zstate2 = node.Z.__getstate__()
if zstate2 != zstate:
panic("BUG: Restructure: node.__getstate__ returns not what "
panic("BUG: node.__getstate__ returns not what "
"we passed into node.__setstate__.\nnode: %r\n"
"__setstate__ <- %r\n__getstate__ -> %r" % (node.Z, zstate, zstate2))
......@@ -514,7 +521,7 @@ def Restructure(ztree, newStructure):
_zbcheck(ztree) # verify ztree after our tweaks
tstruct = StructureOf(ztree, onlyKeys=True)
if tstruct != newStructure:
panic("BUG: Restructure: result structure is not what was"
panic("BUG: result structure is not what was"
" requested:\n%s\n\nwant:\n%s" % (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