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

.

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