Commit 17414964 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 670dda43
......@@ -131,12 +131,12 @@ def topoEncode(treeStruct):
1/0
# IterAllStructs iterates though practically all structures for BTrees with
# specified keys and btree depth up-to maxdepth. Eatch tree node is split by
# up-to maxsplit points.
# AllStructs generates all possible BTree structures for BTrees with specified
# keys and btree depth up-to maxdepth. Eatch tree node is split by up-to
# maxsplit points.
#
# XXX skipped cases
def IterAllStructs(keys, maxdepth, maxsplit):
def AllStructs(keys, maxdepth, maxsplit): # -> i[] of Tree
assert isinstance(maxdepth, int); assert maxdepth >= 0
assert isinstance(maxsplit, int); assert maxsplit >= 0
ks = set(keys)
......@@ -158,15 +158,15 @@ def IterAllStructs(keys, maxdepth, maxsplit):
klo = 0
khi = 0
for tree in _iterAllStructs(klo, khi, keyv, maxdepth, maxsplit):
for tree in _allStructs(klo, khi, keyv, maxdepth, maxsplit):
yield tree
def _iterAllStructs(klo, khi, keyv, maxdepth, maxsplit):
def _allStructs(klo, khi, keyv, maxdepth, maxsplit):
assert klo <= khi
# XXX assert keyv sorted, in [klo, khi)
print('_iterAllStructs [%s, %s) keyv: %r, maxdepth=%d, maxsplit=%d' %
print('_allStructs [%s, %s) keyv: %r, maxdepth=%d, maxsplit=%d' %
(klo, khi, keyv, maxdepth, maxsplit))
for nsplit in range(0, maxsplit+1):
......@@ -183,9 +183,9 @@ def _iterAllStructs(klo, khi, keyv, maxdepth, maxsplit):
# emit Tree -> Trees -> ...
if maxdepth == 0:
continue
ichildrenv = [] # of _iterAllStructs for each child link
ichildrenv = [] # of _allStructs for each child link
for (xlo, xhi) in zip(ksplitv[:-1], ksplitv[1:]): # (klo, s1), (s1, s2), ..., (sN, khi)
ichildrenv.append( _iterAllStructs(
ichildrenv.append( _allStructs(
xlo, xhi, _keyvSliceBy(keyv, xlo, xhi), maxdepth - 1, maxsplit))
for children in itertools.product(*ichildrenv):
......
......@@ -62,7 +62,7 @@ def test_topologyOf():
# T4 T2-T T-T-T6,10 B1-B3-T-T-T T-B7-B11 B5 <-- good
# T4·T2-T·T-T-T6,10·B1-B3-T-T-T·T-B7-B11·B5. <- ?
# T4/T2-T/T-T-T6,10/B1-B3-T-T-T/T-B7-B11/B5 <- ?
# T4/T2-T/T-T-T6,10/B1-B3-T-T-T/T-B7-B11/B5 <- ? y
"""
"""
......@@ -71,11 +71,11 @@ def test_topologyOf():
(((), ()), (6, 10)),
"""
def test_iterAllStructs():
def test_AllStructs():
T = xbtree.Tree
B = xbtree.Bucket
def X(keys, maxdepth, maxsplit):
return list(xbtree.IterAllStructs(keys, maxdepth, maxsplit))
return list(xbtree.AllStructs(keys, maxdepth, maxsplit))
print()
assert X([], 0, 0) == [ T([], B()) ]
......@@ -86,17 +86,16 @@ def test_iterAllStructs():
#assert X([], 0, 1) == [ T([], B()), T([0], B(), B()) ]
assert X([], 1, 0) == [ T([], B()),
assert X([], 1, 0) == X([], 0,0) + [
T([],
T([], B())) ]
T([], B()))
]
assert X([], 2, 0) == [ T([], B()),
T([],
T([], B())),
assert X([], 2, 0) == X([], 1,0) + [
T([],
T([],
T([], B())))
]
]
assert X([1,3], 0, 0) == [ T([], B(1,3)) ]
......
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