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
20a7ea71
Commit
20a7ea71
authored
May 15, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
7305c503
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
8 deletions
+26
-8
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+20
-6
wcfs/internal/xbtree_test.py
wcfs/internal/xbtree_test.py
+6
-2
No files found.
wcfs/internal/xbtree.py
View file @
20a7ea71
...
@@ -495,7 +495,12 @@ def Restructure(ztree, newStructure):
...
@@ -495,7 +495,12 @@ def Restructure(ztree, newStructure):
# AllStructs generates subset of all possible BTree structures for BTrees with
# AllStructs generates subset of all possible BTree structures for BTrees with
# specified keys and btree depth up-to maxdepth. Each tree node is split by
# specified keys and btree depth up-to maxdepth. Each tree node is split by
# up-to maxsplit points.
# up-to maxsplit points.
def
AllStructs
(
keys
,
maxdepth
,
maxsplit
):
# -> i[] of Tree
#
# If allowEmptyBuckets=y tree structures with empty buckets are also generated.
# By default, except for empty-tree case, only tree structures with non-empty
# buckets are generated, because ZODB BTree package misbehaves if it finds an
# empty bucket in a trees. ZODB.BTree._check also asserts if bucket is empty.
def
AllStructs
(
keys
,
maxdepth
,
maxsplit
,
allowEmptyBuckets
=
False
):
# -> i[] of Tree
assert
isinstance
(
maxdepth
,
int
);
assert
maxdepth
>=
0
assert
isinstance
(
maxdepth
,
int
);
assert
maxdepth
>=
0
assert
isinstance
(
maxsplit
,
int
);
assert
maxsplit
>=
0
assert
isinstance
(
maxsplit
,
int
);
assert
maxsplit
>=
0
ks
=
set
(
keys
)
ks
=
set
(
keys
)
...
@@ -517,11 +522,16 @@ def AllStructs(keys, maxdepth, maxsplit): # -> i[] of Tree
...
@@ -517,11 +522,16 @@ def AllStructs(keys, maxdepth, maxsplit): # -> i[] of Tree
klo
=
0
klo
=
0
khi
=
0
khi
=
0
for
tree
in
_allStructs
(
klo
,
khi
,
keyv
,
maxdepth
,
maxsplit
):
# the only possible case for empty tree is T/B
if
not
allowEmptyBuckets
:
yield
Tree
([],
Bucket
())
return
for
tree
in
_allStructs
(
klo
,
khi
,
keyv
,
maxdepth
,
maxsplit
,
allowEmptyBuckets
):
yield
tree
yield
tree
def
_allStructs
(
klo
,
khi
,
keyv
,
maxdepth
,
maxsplit
):
def
_allStructs
(
klo
,
khi
,
keyv
,
maxdepth
,
maxsplit
,
allowEmptyBuckets
):
assert
klo
<=
khi
assert
klo
<=
khi
_assertIncv
(
keyv
)
_assertIncv
(
keyv
)
if
len
(
keyv
)
>
0
:
if
len
(
keyv
)
>
0
:
...
@@ -539,7 +549,11 @@ def _allStructs(klo, khi, keyv, maxdepth, maxsplit):
...
@@ -539,7 +549,11 @@ def _allStructs(klo, khi, keyv, maxdepth, maxsplit):
# emit Tree -> Buckets
# emit Tree -> Buckets
children
=
[]
children
=
[]
for
(
xlo
,
xhi
)
in
zip
(
ksplitv
[:
-
1
],
ksplitv
[
1
:]):
# (klo, s1), (s1, s2), ..., (sN, khi)
for
(
xlo
,
xhi
)
in
zip
(
ksplitv
[:
-
1
],
ksplitv
[
1
:]):
# (klo, s1), (s1, s2), ..., (sN, khi)
children
.
append
(
Bucket
(
*
_keyvSliceBy
(
keyv
,
xlo
,
xhi
)))
bkeyv
=
_keyvSliceBy
(
keyv
,
xlo
,
xhi
)
if
len
(
bkeyv
)
==
0
and
(
not
allowEmptyBuckets
):
break
children
.
append
(
Bucket
(
*
bkeyv
))
else
:
yield
Tree
(
ksplitv
[
1
:
-
1
],
*
children
)
# (s1, s2, ..., sN)
yield
Tree
(
ksplitv
[
1
:
-
1
],
*
children
)
# (s1, s2, ..., sN)
# emit Tree -> Trees -> ...
# emit Tree -> Trees -> ...
...
@@ -548,7 +562,7 @@ def _allStructs(klo, khi, keyv, maxdepth, maxsplit):
...
@@ -548,7 +562,7 @@ def _allStructs(klo, khi, keyv, maxdepth, maxsplit):
ichildrenv
=
[]
# of _allStructs for each child link
ichildrenv
=
[]
# of _allStructs for each child link
for
(
xlo
,
xhi
)
in
zip
(
ksplitv
[:
-
1
],
ksplitv
[
1
:]):
# (klo, s1), (s1, s2), ..., (sN, khi)
for
(
xlo
,
xhi
)
in
zip
(
ksplitv
[:
-
1
],
ksplitv
[
1
:]):
# (klo, s1), (s1, s2), ..., (sN, khi)
ichildrenv
.
append
(
_allStructs
(
ichildrenv
.
append
(
_allStructs
(
xlo
,
xhi
,
_keyvSliceBy
(
keyv
,
xlo
,
xhi
),
maxdepth
-
1
,
maxsplit
))
xlo
,
xhi
,
_keyvSliceBy
(
keyv
,
xlo
,
xhi
),
maxdepth
-
1
,
maxsplit
,
allowEmptyBuckets
))
for
children
in
itertools
.
product
(
*
ichildrenv
):
for
children
in
itertools
.
product
(
*
ichildrenv
):
yield
Tree
(
ksplitv
[
1
:
-
1
],
*
children
)
# (s1, s2, ..., sN)
yield
Tree
(
ksplitv
[
1
:
-
1
],
*
children
)
# (s1, s2, ..., sN)
...
...
wcfs/internal/xbtree_test.py
View file @
20a7ea71
...
@@ -116,10 +116,14 @@ def test_topoEncoding():
...
@@ -116,10 +116,14 @@ def test_topoEncoding():
def
test_allStructs
():
def
test_allStructs
():
T
=
xbtree
.
Tree
T
=
xbtree
.
Tree
B
=
xbtree
.
Bucket
B
=
xbtree
.
Bucket
def
X
(
keys
,
maxdepth
,
maxsplit
):
def
X
(
keys
,
maxdepth
,
maxsplit
,
allowEmptyBuckets
=
True
):
return
list
(
xbtree
.
AllStructs
(
keys
,
maxdepth
,
maxsplit
))
return
list
(
xbtree
.
AllStructs
(
keys
,
maxdepth
,
maxsplit
,
allowEmptyBuckets
))
def
Y
(
keys
,
maxdepth
,
maxsplit
):
return
X
(
keys
,
maxsplit
,
maxsplit
,
allowEmptyBuckets
=
False
)
assert
X
([],
0
,
0
)
==
[
T
([],
B
())
]
assert
X
([],
0
,
0
)
==
[
T
([],
B
())
]
assert
Y
([],
0
,
0
)
==
[
T
([],
B
())
]
assert
X
([
1
],
0
,
0
)
==
[
T
([],
B
(
1
))
]
assert
X
([
1
],
0
,
0
)
==
[
T
([],
B
(
1
))
]
assert
X
([
1
,
3
],
0
,
0
)
==
[
T
([],
B
(
1
,
3
))
]
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