Commit a64f6f45 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 635c20b0
......@@ -129,6 +129,53 @@ def topoEncode(treeStruct):
1/0
# iterAllStructPermutation iterates though all structures for BTrees with
# specified keys and btree depth up-to maxdepth. Eatch tree node is split by
# up-to maxsplit points.
def iterAllStructPermutations(keys, maxdepth, maxsplit):
assert isinstance(maxdepth, int); assert maxdepth >= 0
assert isinstance(maxsplit, int); assert maxsplit >= 0
ks = set(keys)
for k in keys:
assert isinstance(k, int)
assert k in ks # no duplicates
del keys[k]
keyv = list(keys)
keyv.sort()
# initial [lo, hi) covering keys with +-1
klo = -inf
khi = +inf
if len(keyv) > 0:
klo = keyv[0] - 1
khi = keyv[-1] + 1 + 1 # hi is ")", not "]"
_keyvSliceBy(keyv, klo, khi)
def _iterAllStructPermutations(keyv, maxdepth, maxsplit):
for nsplit in range(0, maxsplit):
# _keyvSliceBy returns [] of keys from keyv : k ∈ [klo, khi)
def _keyvSliceBy(keyv, klo, khi):
assert klo <= khi
assert _keyvSorted(keyv)
return list([k for k in keyv if (klo <= k < khi)])
# iterSplitBy iterates through all nsplit splitting of [lo, hi) range.
# hi > lo
# XXX nsplit > ...
def iterSplitBy(lo, hi, nsplit): # -> [] of [lo, s1, s2, ..., sn, hi)
if nsplit == 0:
yield [lo, hi]
return
# XXX
# ---- misc ----
# _indent returns text with each line of it indented with prefix.
......
......@@ -55,6 +55,8 @@ def test_topologyOf():
assert btree.TopoEncodingOf(t) == \
(4,), (2,),(), (),(),(6,10), B(1),B(3),(),(),(), (),B(7),B(11), B(5)
# T4 T2-T T-T-T6,10 B1-B3-T-T-T T-B7-B11 B5
"""
assert xbtree.TopologyOf(t) == ( (4,),
((2,), ()),
......
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