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
a64f6f45
Commit
a64f6f45
authored
May 04, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
635c20b0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
0 deletions
+49
-0
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+47
-0
wcfs/internal/xbtree_test.py
wcfs/internal/xbtree_test.py
+2
-0
No files found.
wcfs/internal/xbtree.py
View file @
a64f6f45
...
...
@@ -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.
...
...
wcfs/internal/xbtree_test.py
View file @
a64f6f45
...
...
@@ -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,), ()),
...
...
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