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
13f4b6df
Commit
13f4b6df
authored
May 25, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
126bbb7a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
34 deletions
+39
-34
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+32
-21
wcfs/internal/xbtree_test.py
wcfs/internal/xbtree_test.py
+7
-13
No files found.
wcfs/internal/xbtree.py
View file @
13f4b6df
...
...
@@ -164,21 +164,31 @@ class Tree(object):
class
Bucket
(
object
):
# .keyv () of keys
# .valuev None | () of values len(.valuev) == len(.keyv)
def
__init__
(
b
,
*
keyv
):
# XXX +values
def
__init__
(
b
,
keyv
,
valuev
):
# XXX syntax sugar for values? (lack of values)?
_assertIncv
(
keyv
)
b
.
keyv
=
tuple
(
keyv
)
if
valuev
is
None
:
b
.
valuev
=
None
else
:
assert
len
(
valuev
)
==
len
(
keyv
)
b
.
valuev
=
tuple
(
valuev
)
def
__hash__
(
b
):
return
hash
(
b
.
keyv
)
# XXX +values
return
hash
(
b
.
keyv
)
^
hash
(
b
.
valuev
)
def
__ne__
(
a
,
b
):
return
not
(
a
==
b
)
def
__eq__
(
a
,
b
):
if
not
isinstance
(
b
,
Bucket
):
return
False
return
a
.
keyv
==
b
.
keyv
return
(
a
.
keyv
==
b
.
keyv
and
a
.
valuev
==
b
.
valuev
)
def
__str__
(
b
):
# XXX +values
return
"B("
+
','
.
join
([
'%s'
%
_
for
_
in
b
.
keyv
])
+
")"
def
__str__
(
b
):
if
b
.
values
is
None
:
kvv
=
[
'%s'
%
k
for
k
in
b
.
keyv
]
else
:
assert
len
(
b
.
keyv
)
==
len
(
b
.
valuev
)
kvv
=
[
'%s:%s'
%
(
k
,
v
)
for
(
k
,
v
)
in
zip
(
b
.
keyv
,
b
.
valuev
)]
return
"B"
+
','
.
join
(
kvv
)
__repr__
=
__str__
def
copy
(
b
):
...
...
@@ -194,14 +204,14 @@ def StructureOf(znode):
if
ztype
.
is_zbucket
:
keys
,
values
=
zbcheck
.
crack_bucket
(
znode
,
ztype
.
is_map
)
if
not
ztype
.
is_map
:
return
Bucket
(
*
keys
)
return
Bucket
(
keys
,
None
)
else
:
return
Bucket
(
keys
,
values
)
# XXX
return
Bucket
(
keys
,
values
)
if
ztype
.
is_ztree
:
kind
,
keys
,
children
=
zbcheck
.
crack_btree
(
znode
,
ztype
.
is_map
)
if
kind
==
zbcheck
.
BTREE_EMPTY
:
return
Tree
([],
Bucket
(
))
# XXX values !None for map
return
Tree
([],
Bucket
(
[],
[]
if
ztype
.
is_map
else
None
))
if
kind
==
zbcheck
.
BTREE_ONE
:
b
=
znode
.
_bucket_type
()
...
...
@@ -802,22 +812,23 @@ def TopoDecode(text, vdecode=int):
raise
TopoDecodeError
(
"incorrect node %s: unknown prefix"
%
qq
(
tnode
))
tkeys
=
tnode
[
1
:]
# e.g. '7,8,9' or '1:a,3:def' or ''
if
tkeys
==
''
:
keyv
=
[]
t
keyv
=
[]
else
:
withV
=
(
typ
is
Bucket
and
':'
in
tkeys
)
tkeyv
=
tkeys
.
split
(
','
)
# e.g. 7 8 9
keyv
=
[]
valuev
=
[]
if
withV
else
None
for
tkey
in
tkeyv
:
ktxt
=
tkey
if
withV
:
ktxt
,
vtxt
=
tkey
.
split
(
':'
)
v
=
vdecode
(
vtxt
)
valuev
.
append
(
v
)
k
=
int
(
ktxt
)
keyv
.
append
(
k
)
withV
=
(
typ
is
Bucket
and
':'
in
tkeys
)
keyv
=
[]
valuev
=
[]
if
withV
else
None
for
tkey
in
tkeyv
:
ktxt
=
tkey
if
withV
:
ktxt
,
vtxt
=
tkey
.
split
(
':'
)
v
=
vdecode
(
vtxt
)
valuev
.
append
(
v
)
k
=
int
(
ktxt
)
keyv
.
append
(
k
)
if
typ
is
Bucket
:
node
=
Bucket
(
*
keyv
)
# XXX valuev
node
=
Bucket
(
keyv
,
valuev
)
else
:
# Tree
nchild
=
len
(
keyv
)
+
1
...
...
wcfs/internal/xbtree_test.py
View file @
13f4b6df
...
...
@@ -34,6 +34,11 @@ import transaction
from
pytest
import
raises
inf
=
float
(
'inf'
)
# T/B are shorthands for Tree and Bucket without values.
# Bv is shorthand for Bucket with values.
T
=
xbtree
.
Tree
B
=
lambda
*
keyv
:
xbtree
.
Bucket
(
keyv
,
None
)
Bv
=
lambda
keyv
,
*
valuev
:
xbtree
.
Bucket
(
keyv
,
valuev
)
# build ztree with known degenerate topology, see:
# https://github.com/zopefoundation/ZODB/commit/6cd24e99f89b
...
...
@@ -42,8 +47,6 @@ 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
))),
...
...
@@ -56,17 +59,14 @@ def buildDegenerateZTree():
def
test_structureOf
():
T
=
xbtree
.
Tree
B
=
xbtree
.
Bucket
# empty tree
t
=
LOBTree
()
assert
xbtree
.
StructureOf
(
t
)
==
T
([],
B
(
))
assert
xbtree
.
StructureOf
(
t
)
==
T
([],
B
v
([]
))
# tree with 1 k->v
t
=
LOBTree
()
t
[
10
]
=
'hello'
assert
xbtree
.
StructureOf
(
t
)
==
T
([],
B
(
10
))
assert
xbtree
.
StructureOf
(
t
)
==
T
([],
B
v
([
10
],
'hello'
))
# known degenerate topology
t
=
buildDegenerateZTree
()
...
...
@@ -80,8 +80,6 @@ def test_structureOf():
T
([],
B
(
11
)))
))
def
test_topoEncoding
():
T
=
xbtree
.
Tree
B
=
xbtree
.
Bucket
def
X
(
tree
):
topo
=
xbtree
.
TopoEncode
(
tree
)
t2
=
xbtree
.
TopoDecode
(
topo
)
...
...
@@ -115,8 +113,6 @@ def test_topoEncoding():
def
test_allStructs
():
T
=
xbtree
.
Tree
B
=
xbtree
.
Bucket
# X = AllStructs(..., allowEmptyBuckets=True)
# Y = AllStructs(..., allowEmptyBuckets=False)
# XY = X = Y + assert X == Y
...
...
@@ -707,8 +703,6 @@ def test_restructure():
def
test_walkBFS
():
T
=
xbtree
.
Tree
B
=
xbtree
.
Bucket
R
=
xbtree
.
_Range
# XXX ø
...
...
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