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
bd345fba
Commit
bd345fba
authored
May 07, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
edb4941e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
1 deletion
+36
-1
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+35
-1
wcfs/internal/xbtree_test.py
wcfs/internal/xbtree_test.py
+1
-0
No files found.
wcfs/internal/xbtree.py
View file @
bd345fba
...
...
@@ -181,7 +181,29 @@ def StructureOf(node):
# See top-level docstring for what topology is.
def
TopoEncode
(
tree
):
assert
isinstance
(
tree
,
Tree
)
topo
=
'zzz'
# XXX
topo
=
''
# breadth-first traversal of the tree with '/' injected in between layers
queue
=
[
tree
,
'/'
]
while
1
:
x
=
queue
.
pop
(
0
)
if
x
==
'/'
:
if
len
(
queue
)
==
0
:
break
# it was last '/'
topo
+=
'/'
queue
.
append
(
'/'
)
# add / after all queued nodes of next layer
continue
node
=
x
assert
isinstance
(
node
,
(
Tree
,
Bucket
))
tnode
=
(
'T'
if
isinstance
(
node
,
Tree
)
else
'B'
)
+
\
(
','
.
join
([
'%d'
%
_
for
_
in
node
.
keyv
]))
if
len
(
topo
)
!=
0
and
topo
[
-
1
]
!=
'/'
:
topo
+=
'-'
topo
+=
tnode
if
isinstance
(
node
,
Tree
):
queue
+=
node
.
children
if
1
:
# debug
t2
=
TopoDecode
(
topo
)
...
...
@@ -198,6 +220,18 @@ def TopoDecode(text):
# _iterBFS iterates tree nodes in breadth-first order.
def
_iterBFS
(
tree
):
# -> i[] of tree nodes
assert
isinstance
(
tree
,
Tree
)
queue
=
[
tree
]
while
len
(
queue
)
>
0
:
node
=
queue
.
pop
(
0
)
assert
isinstance
(
node
,
(
Tree
,
Bucket
))
yield
node
if
isinstance
(
node
,
Tree
):
queue
+=
node
.
children
# Restructure reorganizes BTree instance (not Tree) according to new structure.
def
Restructure
(
tree
,
newStructure
):
assert
istree
(
tree
)
...
...
wcfs/internal/xbtree_test.py
View file @
bd345fba
...
...
@@ -88,6 +88,7 @@ def test_topoEncoding():
assert
X
(
T
([],
B
(
1
,
3
)))
==
'T/B1,3'
assert
X
(
T
([],
T
([],
B
())))
==
'T/T/B'
# XXX two B under same T
# XXX more
assert
X
(
T
([
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