Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
wendelin.core
Commits
846e08c0
Commit
846e08c0
authored
May 18, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
e0cbe930
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
1 deletion
+30
-1
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+21
-0
wcfs/internal/xbtree_test.py
wcfs/internal/xbtree_test.py
+9
-1
No files found.
wcfs/internal/xbtree.py
View file @
846e08c0
...
...
@@ -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 ----
...
...
wcfs/internal/xbtree_test.py
View file @
846e08c0
...
...
@@ -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
)
==
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment