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
75192d09
Commit
75192d09
authored
May 12, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
4d10656a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
7 deletions
+73
-7
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+7
-3
wcfs/internal/xbtree_test.py
wcfs/internal/xbtree_test.py
+66
-4
No files found.
wcfs/internal/xbtree.py
View file @
75192d09
...
...
@@ -456,7 +456,12 @@ def _walkBFS(tree): # i[] of [](of nodes on each level)
for
level
in
__walkBFS
(
tree
):
yield
tuple
(
rn
.
node
for
rn
in
level
)
def
__walkBFS
(
tree
):
# i[] of [](of _NodeInRange)
# _zwalkBFS, similarly to _walkBFS, walks ZODB BTree in breadth-first order layer by layer.
def
_zwalkBFS
(
ztree
):
# i[] of [](of nodes on each level)
for
zlevel
in
__zwalkBFS
(
ztree
):
yield
tuple
(
rn
.
node
for
rn
in
zlevel
)
def
__walkBFS
(
tree
):
# i[] of [](of _NodeInRange on each level)
assert
isinstance
(
tree
,
Tree
)
currentq
=
[]
nextq
=
[
_NodeInRange
(
_Range
(
-
inf
,
+
inf
),
tree
)]
...
...
@@ -474,8 +479,7 @@ def __walkBFS(tree): # i[] of [](of _NodeInRange)
for
i
in
range
(
len
(
rv
)):
nextq
.
append
(
_NodeInRange
(
_Range
(
*
rv
[
i
]),
rn
.
node
.
children
[
i
]))
# _zwalkBFS, similarly to _walkBFS, walks ZODB BTree in breadth-first order layer by layer.
def
_zwalkBFS
(
ztree
):
# i[] of [](of nodes on each level)
def
__zwalkBFS
(
ztree
):
# i[] of [](of _NodeInRange on each level)
_
=
_zclassify
(
ztree
)
assert
_
.
is_ztree
...
...
wcfs/internal/xbtree_test.py
View file @
75192d09
...
...
@@ -28,6 +28,26 @@ from BTrees import check as bcheck
from
persistent
import
Persistent
inf
=
float
(
'inf'
)
# build ztree with known degenerate topology, see:
# https://github.com/zopefoundation/ZODB/commit/6cd24e99f89b
# https://github.com/zopefoundation/BTrees/blob/4.7.2-1-g078ba60/BTrees/tests/testBTrees.py#L20
def
buildDegenerateZTree
():
ztree
,
keys
=
testBTrees
.
DegenerateBTree
(
"testBasicOps"
).
_build_degenerate_tree
()
assert
keys
==
[
1
,
3
,
5
,
7
,
11
]
T
=
xbtree
.
Tree
B
=
xbtree
.
Bucket
assert
xbtree
.
StructureOf
(
ztree
)
==
T
([
4
],
T
([
2
],
T
([],
B
(
1
)),
T
([],
B
(
3
))),
T
([],
T
([
6
,
10
],
T
([],
T
([],
B
(
5
))),
T
([],
B
(
7
)),
T
([],
B
(
11
)))
))
return
ztree
def
test_structureOf
():
T
=
xbtree
.
Tree
B
=
xbtree
.
Bucket
...
...
@@ -42,10 +62,7 @@ def test_structureOf():
assert
xbtree
.
StructureOf
(
t
)
==
T
([],
B
(
10
))
# known degenerate topology, see:
# https://github.com/zopefoundation/ZODB/commit/6cd24e99f89b
# https://github.com/zopefoundation/BTrees/blob/4.7.2-1-g078ba60/BTrees/tests/testBTrees.py#L20
t
,
keys
=
testBTrees
.
DegenerateBTree
(
"testBasicOps"
).
_build_degenerate_tree
()
assert
keys
==
[
1
,
3
,
5
,
7
,
11
]
t
=
buildDegenerateZTree
()
assert
xbtree
.
StructureOf
(
t
)
==
T
([
4
],
T
([
2
],
T
([],
B
(
1
)),
T
([],
B
(
3
))),
...
...
@@ -400,6 +417,9 @@ def test_walkBFS():
B
=
xbtree
.
Bucket
R
=
xbtree
.
_Range
# XXX ø
# XXX 1 k->v
bl
=
B
();
br
=
B
()
tl
=
T
([],
bl
)
tr
=
T
([],
br
)
...
...
@@ -430,6 +450,48 @@ def test_walkBFS():
# XXX more tests?
def
test_zwalkBFS
():
zt
=
buildDegenerateZTree
()
# T return kind + keys of a ztree node
def
T
(
ztree
):
assert
isinstance
(
ztree
,
IITreeSet
)
kind
,
keys
,
kids
=
zbcheck
.
crack_btree
(
ztree
)
return
(
kind
,
keys
)
# B returns keys from zbucket node
def
B
(
zbucket
):
assert
isinstance
(
zbucket
,
IISet
)
keys
,
_
=
zbcheck
.
crack_bucket
(
zbucket
)
return
keys
zwalkv
=
list
(
xbtree
.
__zwalkBFS
(
zt
))
assert
len
(
zwalkv
)
==
6
# [-∞,∞)T4,
# [-∞,4)T2, [4,∞)T
# [-∞,2)T, [2,4)T, [4,∞)T6,10
# [-∞,2)B1, [2,4)B3, [4,6)T, [6,10)T, [10,∞]T
# [4,6)T, [6,10)B7, [10,∞)B11
# [4,6)B5
_
=
zwalkv
[
0
]
# [-∞,∞)T4,
assert
len
(
_
)
==
1
assert
_
[
0
].
range
==
R
(
-
inf
,
inf
)
assert
T
(
_
[
0
].
node
)
==
(
BTREE_NORMAL
,
[
4
])
_
=
zwalkv
[
1
]
# [-∞,4)T2, [4,∞)T
assert
len
(
_
)
==
2
assert
_
[
0
].
range
==
R
(
-
inf
,
4
)
assert
T
(
_
[
0
].
node
)
==
(
BTREE_NORMAL
,
[
2
])
assert
_
[
1
].
range
==
R
(
4
,
inf
)
assert
T
(
_
[
1
].
node
)
==
(
BTREE_NORMAL
,
[])
_
=
zwalkv
[
2
]
# [-∞,2)T, [2,4)T, [4,∞)T6,10
assert
len
(
_
)
==
3
# XXX
def
test_keyvSliceBy
():
X
=
xbtree
.
_keyvSliceBy
...
...
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