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
b7de2f10
Commit
b7de2f10
authored
Apr 30, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
a959e43a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
6 deletions
+32
-6
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+27
-2
wcfs/internal/xbtree_test.py
wcfs/internal/xbtree_test.py
+5
-4
No files found.
wcfs/internal/xbtree.py
View file @
b7de2f10
...
...
@@ -52,11 +52,20 @@ class Tree:
def
__hash__
(
t
):
return
hash
(
t
.
keyv
)
^
hash
(
t
.
children
)
# XXX children ^^^
def
__str__
(
t
):
s
=
"T(["
+
","
.
join
([
'%s'
%
_
for
_
in
t
.
keyv
])
+
"]"
for
ch
in
t
.
children
:
s
+=
",
\
n
"
s
+=
_indent
(
' '
*
4
,
str
(
ch
))
s
+=
")"
return
s
__repr__
=
__str__
# Bucked represents a bucket node.
class
Bucket
:
# .keyv () of keys
def
__init__
(
b
,
keyv
):
def
__init__
(
b
,
*
keyv
):
# XXX *keyv -> keyv ?
# XXX assert keyv ↑
b
.
keyv
=
tuple
(
keyv
)
...
...
@@ -67,6 +76,11 @@ class Bucket:
def
__hash__
(
b
):
return
hash
(
b
.
keyv
)
def
__str__
(
b
):
return
"B("
+
','
.
join
([
'%s'
%
_
for
_
in
b
.
keyv
])
+
")"
__repr__
=
__str__
# StructureOf returns internal structure of a tree.
def
StructureOf
(
node
):
...
...
@@ -80,7 +94,7 @@ def StructureOf(node):
if
is_bucket
:
keys
,
_
=
bcheck
.
crack_bucket
(
node
,
is_map
)
return
Bucket
(
keys
)
return
Bucket
(
*
keys
)
if
is_tree
:
kind
,
keys
,
children
=
bcheck
.
crack_btree
(
node
,
is_map
)
...
...
@@ -108,3 +122,14 @@ def TypologyOf(tree):
1
/
0
treeStruct
=
StructureOf
(
tree
)
# XXX convert struct -> topology
# ---- misc ----
# _indent returns text with each line of it indented with prefix.
def
_indent
(
prefix
,
text
):
# -> text
textv
=
text
.
split
(
'
\
n
'
)
textv
=
[
prefix
+
_
for
_
in
textv
]
text
=
'
\
n
'
.
join
(
textv
)
return
text
wcfs/internal/xbtree_test.py
View file @
b7de2f10
...
...
@@ -23,6 +23,7 @@ from BTrees.tests import testBTrees
def
test_topologyOf
():
T
=
xbtree
.
Tree
B
=
xbtree
.
Bucket
# XXX empty
...
...
@@ -36,12 +37,12 @@ def test_topologyOf():
assert
xbtree
.
StructureOf
(
t
)
==
T
([
4
],
T
([
2
],
T
([]
),
T
([]
)),
T
([]
,
B
(
1
)),
T
([],
B
(
3
)
)),
T
([],
T
([
6
,
10
],
T
([],
T
([])),
T
([]),
T
([]))
))
T
([],
T
([]
,
B
(
5
)
)),
T
([]
,
B
(
7
)
),
T
([]
,
B
(
11
)
))
))
"""
assert xbtree.TopologyOf(t) == ( (4,),
...
...
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