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
17414964
Commit
17414964
authored
May 06, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
670dda43
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
18 deletions
+17
-18
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+9
-9
wcfs/internal/xbtree_test.py
wcfs/internal/xbtree_test.py
+8
-9
No files found.
wcfs/internal/xbtree.py
View file @
17414964
...
...
@@ -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
_
iterA
llStructs
(
klo
,
khi
,
keyv
,
maxdepth
,
maxsplit
):
for
tree
in
_
a
llStructs
(
klo
,
khi
,
keyv
,
maxdepth
,
maxsplit
):
yield
tree
def
_
iterA
llStructs
(
klo
,
khi
,
keyv
,
maxdepth
,
maxsplit
):
def
_
a
llStructs
(
klo
,
khi
,
keyv
,
maxdepth
,
maxsplit
):
assert
klo
<=
khi
# XXX assert keyv sorted, in [klo, khi)
print
(
'_
iterA
llStructs [%s, %s) keyv: %r, maxdepth=%d, maxsplit=%d'
%
print
(
'_
a
llStructs [%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 _
iterA
llStructs for each child link
ichildrenv
=
[]
# of _
a
llStructs for each child link
for
(
xlo
,
xhi
)
in
zip
(
ksplitv
[:
-
1
],
ksplitv
[
1
:]):
# (klo, s1), (s1, s2), ..., (sN, khi)
ichildrenv
.
append
(
_
iterA
llStructs
(
ichildrenv
.
append
(
_
a
llStructs
(
xlo
,
xhi
,
_keyvSliceBy
(
keyv
,
xlo
,
xhi
),
maxdepth
-
1
,
maxsplit
))
for
children
in
itertools
.
product
(
*
ichildrenv
):
...
...
wcfs/internal/xbtree_test.py
View file @
17414964
...
...
@@ -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_
iter
AllStructs
():
def
test_AllStructs
():
T
=
xbtree
.
Tree
B
=
xbtree
.
Bucket
def
X
(
keys
,
maxdepth
,
maxsplit
):
return
list
(
xbtree
.
Iter
AllStructs
(
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
))
]
...
...
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