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
3ebb53cc
Commit
3ebb53cc
authored
May 07, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
ff58a7c0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
4 deletions
+50
-4
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+49
-3
wcfs/internal/xbtree_test.py
wcfs/internal/xbtree_test.py
+1
-1
No files found.
wcfs/internal/xbtree.py
View file @
3ebb53cc
...
@@ -79,6 +79,7 @@ from __future__ import print_function, absolute_import
...
@@ -79,6 +79,7 @@ from __future__ import print_function, absolute_import
from
BTrees
import
check
as
bcheck
from
BTrees
import
check
as
bcheck
from
golang
import
panic
from
golang
import
panic
from
golang.gcompat
import
qq
import
itertools
import
itertools
import
re
import
re
inf
=
float
(
'inf'
)
inf
=
float
(
'inf'
)
...
@@ -178,7 +179,7 @@ def StructureOf(node):
...
@@ -178,7 +179,7 @@ def StructureOf(node):
# TopoEncode returns topology encoding for internal structure of the tree.
# TopoEncode returns topology encoding for internal structure of the tree.
#
#
# See top-level docstring for
what topology is
.
# See top-level docstring for
description of topology encoding
.
def
TopoEncode
(
tree
):
def
TopoEncode
(
tree
):
assert
isinstance
(
tree
,
Tree
)
assert
isinstance
(
tree
,
Tree
)
topo
=
''
topo
=
''
...
@@ -214,9 +215,54 @@ def TopoEncode(tree):
...
@@ -214,9 +215,54 @@ def TopoEncode(tree):
# TopoDecode decodes topology-encoded text into Tree structure.
# TopoDecode decodes topology-encoded text into Tree structure.
#
#
# XXX see -> ?
# See top-level docstring for description of topology encoding.
class
TopoDecodeError
(
Exception
):
pass
def
TopoDecode
(
text
):
def
TopoDecode
(
text
):
return
Tree
([],
Bucket
())
# XXX stub
levelv
=
text
.
split
(
'/'
)
# T3/T-T/B1-T5/B-B7,8,9 -> T3 T-T B1-T5 B-B7,8,9
# build nodes from bottop-up
currentv
=
[]
# of nodes on current level (that we are building)
bottomq
=
[]
# of nodes below current level that we are building
# shrinks as fifo as nodes added to currentv link to bottom
while
len
(
levelv
)
>
0
:
level
=
levelv
.
pop
()
# e.g. B1-T5
tnodev
=
level
.
split
(
'-'
)
# e.g. B1 T5
bottomq
=
currentv
currentv
=
[]
for
tnode
in
tnodev
:
if
tnode
[:
1
]
==
'T'
:
typ
=
Tree
elif
tnode
[:
1
]
==
'B'
:
typ
=
Bucket
else
:
raise
TopoDecodeError
(
"incorrect node %s: unknown prefix"
%
qq
(
tnode
))
tkeyv
=
tnode
[
1
:].
split
(
','
)
# e.g. 7 8 9
keyv
=
[
int
(
_
)
for
_
in
tkeyv
]
if
typ
is
Bucket
:
node
=
Bucket
(
*
keyv
)
else
:
# Tree
nchild
=
len
(
keyv
)
+
1
if
len
(
bottomq
)
<
nchild
:
raise
TopoDecodeError
(
"node %s at level %d: next level does not have enough children to link to"
%
(
qq
(
tnode
),
len
(
levelv
)
+
1
))
children
=
bottomq
[:
nchild
]
bottomq
=
bottomq
[
nchild
:]
node
=
Tree
(
keyv
,
*
children
)
currentv
.
append
(
node
)
if
len
(
bottomq
)
!=
0
:
raise
TopoDecodeError
(
"level %d does not link to all nodes in the next level"
%
len
(
levelv
+
1
))
if
len
(
currentv
)
!=
0
:
raise
TopoDecodeError
(
"first level has %d entries; must be 1"
%
len
(
currentv
))
root
=
currentv
[
0
]
return
root
# Restructure reorganizes BTree instance (not Tree) according to new structure.
# Restructure reorganizes BTree instance (not Tree) according to new structure.
...
...
wcfs/internal/xbtree_test.py
View file @
3ebb53cc
...
@@ -63,7 +63,7 @@ def test_topoEncoding():
...
@@ -63,7 +63,7 @@ def test_topoEncoding():
def
X
(
tree
):
def
X
(
tree
):
topo
=
xbtree
.
TopoEncode
(
tree
)
topo
=
xbtree
.
TopoEncode
(
tree
)
t2
=
xbtree
.
TopoDecode
(
topo
)
t2
=
xbtree
.
TopoDecode
(
topo
)
#assert t2 == tree # XXX reenabl
e
assert
t2
==
tre
e
return
topo
return
topo
assert
X
(
T
([],
B
()))
==
'T/B'
assert
X
(
T
([],
B
()))
==
'T/B'
...
...
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