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
7cdbd680
Commit
7cdbd680
authored
May 22, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
71354250
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
27 deletions
+30
-27
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+30
-27
No files found.
wcfs/internal/xbtree.py
View file @
7cdbd680
...
...
@@ -607,33 +607,7 @@ def _iterSplitKeyvByN(lo, hi, keyv, nsplit): # -> i[] of [lo, s1, s2, ..., sn, h
yield
[
lo
]
+
tail
# ---- topology encoding ----
# TopoEncode returns topology encoding for internal structure of the tree.
#
# See top-level docstring for description of topology encoding.
def
TopoEncode
(
tree
):
assert
isinstance
(
tree
,
Tree
)
topo
=
''
# breadth-first traversal of the tree with '/' injected in between layers
for
nodev
in
_walkBFS
(
tree
):
if
len
(
topo
)
!=
0
:
topo
+=
'/'
tnodev
=
[]
for
node
in
nodev
:
assert
isinstance
(
node
,
(
Tree
,
Bucket
))
tnode
=
(
'T'
if
isinstance
(
node
,
Tree
)
else
'B'
)
+
\
(
','
.
join
([
'%d'
%
_
for
_
in
node
.
keyv
]))
tnodev
.
append
(
tnode
)
topo
+=
'-'
.
join
(
tnodev
)
if
1
:
# make sure that every topology we emit, can be loaded back
t2
=
TopoDecode
(
topo
)
if
t2
!=
tree
:
panic
(
"BUG: TopoEncode: D(E(·)) != identity
\
n
· = %s
\
n
D(E(·) = %s"
%
(
tree
,
t2
))
return
topo
# ---- treewalk ----
# _Range represents a range under which a node is placed in its tree.
class
_Range
:
...
...
@@ -752,6 +726,35 @@ def __zwalkBFS(ztree): # i[] of [](of _NodeInRange on each level)
nextq
.
append
(
_NodeInRange
(
_Range
(
*
rv
[
i
]),
children
[
i
]))
# ---- topology encoding ----
# TopoEncode returns topology encoding for internal structure of the tree.
#
# See top-level docstring for description of topology encoding.
def
TopoEncode
(
tree
):
assert
isinstance
(
tree
,
Tree
)
topo
=
''
# breadth-first traversal of the tree with '/' injected in between layers
for
nodev
in
_walkBFS
(
tree
):
if
len
(
topo
)
!=
0
:
topo
+=
'/'
tnodev
=
[]
for
node
in
nodev
:
assert
isinstance
(
node
,
(
Tree
,
Bucket
))
tnode
=
(
'T'
if
isinstance
(
node
,
Tree
)
else
'B'
)
+
\
(
','
.
join
([
'%d'
%
_
for
_
in
node
.
keyv
]))
tnodev
.
append
(
tnode
)
topo
+=
'-'
.
join
(
tnodev
)
if
1
:
# make sure that every topology we emit, can be loaded back
t2
=
TopoDecode
(
topo
)
if
t2
!=
tree
:
panic
(
"BUG: TopoEncode: D(E(·)) != identity
\
n
· = %s
\
n
D(E(·) = %s"
%
(
tree
,
t2
))
return
topo
# TopoDecode decodes topology-encoded text into Tree structure.
#
# See top-level docstring for description of topology encoding.
...
...
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