Commit 75192d09 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 4d10656a
......@@ -456,7 +456,12 @@ def _walkBFS(tree): # i[] of [](of nodes on each level)
for level in __walkBFS(tree):
yield tuple(rn.node for rn in level)
def __walkBFS(tree): # i[] of [](of _NodeInRange)
# _zwalkBFS, similarly to _walkBFS, walks ZODB BTree in breadth-first order layer by layer.
def _zwalkBFS(ztree): # i[] of [](of nodes on each level)
for zlevel in __zwalkBFS(ztree):
yield tuple(rn.node for rn in zlevel)
def __walkBFS(tree): # i[] of [](of _NodeInRange on each level)
assert isinstance(tree, Tree)
currentq = []
nextq = [_NodeInRange(_Range(-inf,+inf), tree)]
......@@ -474,8 +479,7 @@ def __walkBFS(tree): # i[] of [](of _NodeInRange)
for i in range(len(rv)):
nextq.append(_NodeInRange(_Range(*rv[i]), rn.node.children[i]))
# _zwalkBFS, similarly to _walkBFS, walks ZODB BTree in breadth-first order layer by layer.
def _zwalkBFS(ztree): # i[] of [](of nodes on each level)
def __zwalkBFS(ztree): # i[] of [](of _NodeInRange on each level)
_ = _zclassify(ztree)
assert _.is_ztree
......
......@@ -28,6 +28,26 @@ from BTrees import check as bcheck
from persistent import Persistent
inf = float('inf')
# build ztree with known degenerate topology, see:
# https://github.com/zopefoundation/ZODB/commit/6cd24e99f89b
# https://github.com/zopefoundation/BTrees/blob/4.7.2-1-g078ba60/BTrees/tests/testBTrees.py#L20
def buildDegenerateZTree():
ztree, keys = testBTrees.DegenerateBTree("testBasicOps")._build_degenerate_tree()
assert keys == [1, 3, 5, 7, 11]
T = xbtree.Tree
B = xbtree.Bucket
assert xbtree.StructureOf(ztree) == T([4],
T([2],
T([], B(1)), T([], B(3))),
T([],
T([6, 10],
T([], T([], B(5))),
T([], B(7)),
T([], B(11))) ))
return ztree
def test_structureOf():
T = xbtree.Tree
B = xbtree.Bucket
......@@ -42,10 +62,7 @@ def test_structureOf():
assert xbtree.StructureOf(t) == T([], B(10))
# known degenerate topology, see:
# https://github.com/zopefoundation/ZODB/commit/6cd24e99f89b
# https://github.com/zopefoundation/BTrees/blob/4.7.2-1-g078ba60/BTrees/tests/testBTrees.py#L20
t, keys = testBTrees.DegenerateBTree("testBasicOps")._build_degenerate_tree()
assert keys == [1, 3, 5, 7, 11]
t = buildDegenerateZTree()
assert xbtree.StructureOf(t) == T([4],
T([2],
T([], B(1)), T([], B(3))),
......@@ -400,6 +417,9 @@ def test_walkBFS():
B = xbtree.Bucket
R = xbtree._Range
# XXX ø
# XXX 1 k->v
bl = B(); br = B()
tl = T([], bl)
tr = T([], br)
......@@ -430,6 +450,48 @@ def test_walkBFS():
# XXX more tests?
def test_zwalkBFS():
zt = buildDegenerateZTree()
# T return kind + keys of a ztree node
def T(ztree):
assert isinstance(ztree, IITreeSet)
kind, keys, kids = zbcheck.crack_btree(ztree)
return (kind, keys)
# B returns keys from zbucket node
def B(zbucket):
assert isinstance(zbucket, IISet)
keys, _ = zbcheck.crack_bucket(zbucket)
return keys
zwalkv = list(xbtree.__zwalkBFS(zt))
assert len(zwalkv) == 6 # [-∞,∞)T4,
# [-∞,4)T2, [4,∞)T
# [-∞,2)T, [2,4)T, [4,∞)T6,10
# [-∞,2)B1, [2,4)B3, [4,6)T, [6,10)T, [10,∞]T
# [4,6)T, [6,10)B7, [10,∞)B11
# [4,6)B5
_ = zwalkv[0] # [-∞,∞)T4,
assert len(_) == 1
assert _[0].range == R(-inf, inf)
assert T(_[0].node) == (BTREE_NORMAL, [4])
_ = zwalkv[1] # [-∞,4)T2, [4,∞)T
assert len(_) == 2
assert _[0].range == R(-inf, 4)
assert T(_[0].node) == (BTREE_NORMAL, [2])
assert _[1].range == R(4, inf)
assert T(_[1].node) == (BTREE_NORMAL, [])
_ = zwalkv[2] # [-∞,2)T, [2,4)T, [4,∞)T6,10
assert len(_) == 3
# XXX
def test_keyvSliceBy():
X = xbtree._keyvSliceBy
......
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