Commit 61eeb509 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3913a125
......@@ -731,7 +731,7 @@ def __zwalkBFS(ztree): # i[] of [](of _NodeInRange on each level)
# TopoEncode returns topology encoding for internal structure of the tree.
#
# See top-level docstring for description of topology encoding.
def TopoEncode(tree):
def TopoEncode(tree, vencode=lambda v: '%d' % v): # XXX vencode document
assert isinstance(tree, Tree)
topo = ''
......@@ -742,8 +742,23 @@ def TopoEncode(tree):
tnodev = []
for node in nodev:
assert isinstance(node, (Tree, Bucket))
tnode = ('T' if isinstance(node, Tree) else 'B') + \
(','.join(['%d' % _ for _ in node.keyv]))
tnode = ('T' if isinstance(node, Tree) else 'B')
if isinstance(node, Bucket) and node.valuev is not None:
# bucket with key and values
assert len(node.valuev) == len(node.keyv)
vtxtv = []
for v in node.valuev:
vtxt = vencode(v)
assert ' ' not in vtxt
assert ':' not in vtxt
assert ',' not in vtxt
assert '-' not in vtxt
tnode += ','.join(['%d:%s' % (k,vtxt)
for (k,vtxt) in zip(node.keyv, vtxtv)])
else:
# tree or bucket with keys
tnode += ','.join(['%d' % _ for _ in node.keyv])
tnodev.append(tnode)
topo += '-'.join(tnodev)
......@@ -761,6 +776,7 @@ class TopoDecodeError(Exception):
pass
def TopoDecode(text, vdecode=int): # XXX vdecode - document
levelv = text.split('/') # T3/T-T/B1:a-T5/B-B7,8,9 -> T3 T-T B1:a-T5 B-B7,8,9
# XXX forbid mixing buckets-with-value with buckets-without-value?
# build nodes from bottom-up
currentv = [] # of nodes on current level (that we are building)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment