Commit 846e08c0 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e0cbe930
......@@ -556,6 +556,27 @@ def _iterSplitByN(lo, hi, nsplit): # -> i[] of [lo, s1, s2, ..., sn, hi)
for tail in _iterSplitByN(s, hi, nsplit-1):
yield [lo] + tail
# _iterSplitKeyvByN is similar to _iterSplitByN but makes sure that every
# splitted range contains at least one key from keyv.
def _iterSplitKeyvByN(lo, hi, keyv, nsplit): # -> i[] of [lo, s1, s2, ..., sn, hi)
#print('_iterSplitKeyvByN [%s, %s) keyv=%r nsplit=%r' % (lo, hi, keyv, nsplit))
assert lo <= hi
assert 0 <= nsplit
_assertIncv(keyv)
assert lo <= keyv[0]
assert keyv[-1] < hi
if nsplit >= len(keyv):
return # no split exists
if nsplit == 0:
yield [lo, hi]
return
for i in range(len(keyv)-nsplit):
for s in range(keyv[i]+1, keyv[i+1]+1): # (ki, k_{i+1}]
for tail in _iterSplitKeyvByN(s, hi, keyv[i+1:], nsplit-1):
yield [lo] + tail
# ---- topology encoding ----
......
......@@ -823,7 +823,6 @@ def test_iterSplitByN():
def X(lo, hi, nsplit):
return tuple(xbtree._iterSplitByN(lo, hi, nsplit))
assert X(0,0, 0) == ( [0,0], )
assert X(0,0, 1) == ()
assert X(0,1, 0) == ( [0,1], )
......@@ -851,3 +850,12 @@ def test_iterSplitByN():
assert X(0,5, 4) == ( [0,1,2,3,4,5], )
assert X(0,5, 5) == ()
def test_iterSplitKeyvByN():
keyv = [1,3,4]
def X(lo, hi, nsplit):
return tuple(xbtree._iterSplitKeyvByN(lo, hi, keyv, nsplit))
assert X(0,7, 0) == ( [0,7], )
assert X(0,7, 1) == ( [0,2,7], [0,3,7], [0,4,7] )
assert X(0,7, 2) == ( [0,2,4,7], [0,3,4,7] )
assert X(0,7, 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