Commit 6c65f491 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 07e27e54
......@@ -77,7 +77,7 @@ in left-to-right order.
from __future__ import print_function, absolute_import
from BTrees import check as bcheck
from BTrees import check as zbcheck
from golang import func, panic
from golang.gcompat import qq
import itertools
......@@ -105,7 +105,6 @@ class Tree(object):
# assert children keys are consistent
v = [-inf] + keyv + [+inf]
for i, (klo, khi) in enumerate(zip(v[:-1], v[1:])): # (klo, khi) = [] of (k_i, k_{i+1})
child = children[i]
for k in children[i].keyv:
if not (klo <= k < khi):
panic("children[%d] key %d is outside key range [%s, %s)" % (i, k, klo, khi))
......@@ -156,39 +155,39 @@ class Bucket(object):
# StructureOf returns internal structure of a BTree.
#
# The structure is represented as Tree and Bucket nodes.
def StructureOf(node):
typ = type(node)
def StructureOf(znode):
typ = type(znode)
is_tree = ("Tree" in typ.__name__)
is_set = ("Set" in typ.__name__)
is_bucket = (("Bucket" in typ.__name__) or re.match("..Set", typ.__name__))
is_map = (not is_set)
if is_bucket:
keys, _ = bcheck.crack_bucket(node, is_map)
keys, _ = zbcheck.crack_bucket(znode, is_map)
return Bucket(*keys)
if is_tree:
kind, keys, children = bcheck.crack_btree(node, is_map)
if kind == bcheck.BTREE_EMPTY:
kind, keys, children = zbcheck.crack_btree(znode, is_map)
if kind == zbcheck.BTREE_EMPTY:
return Tree([], Bucket())
if kind == bcheck.BTREE_ONE:
b = node._bucket_type()
if kind == zbcheck.BTREE_ONE:
b = znode._bucket_type()
b.__setstate__(keys) # it is keys+values for BTREE_ONE case
return Tree([], StructureOf(b))
if kind == bcheck.BTREE_NORMAL:
if kind == zbcheck.BTREE_NORMAL:
return Tree(keys, *[StructureOf(_) for _ in children])
panic("bad tree kind %r" % kind)
panic("unknown node type %r" % typ)
panic("unknown znode type %r" % typ)
# Restructure reorganizes ZODB BTree instance (not Tree) according to specified
# structure.
def Restructure(ztree, newStructure):
assert istree(ztree) # XXX -> use bcheck.classify
assert istree(ztree) # XXX -> use zbcheck.classify
assert isinstance(newStructure, Tree)
1/0
......@@ -322,7 +321,7 @@ def TopoEncode(tree):
# _walkBFS walks tree in breadth-first order layer by layer.
def _walkBFS(tree): # i[] of [](of nodes on each level)
assert isinstance(tree, Tree)
currentv = []
currentq = []
nextq = [tree]
while len(nextq) > 0:
yield tuple(nextq)
......@@ -410,9 +409,10 @@ def _assertIncv(v):
prev = v[i]
# _bcheck performs checks on ztree provided by ZODB packages.
# the checks are what BTree.check and node._check() provide.
class _ZChecker(_bcheck.Checker):
# _bcheck performs full consistency checks on ztree provided by ZODB.
#
# The checks are what is provided by BTree.check and node._check().
class _ZChecker(zbcheck.Checker):
def visit_btree(self, obj, *argv):
super(_ZChecker, self).visit_btree(obj, *argv)
obj._check() # also check internal C-level pointers consistency
......
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