Commit 1e3b1d2f authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 57322f77
......@@ -781,6 +781,11 @@ def TopoEncode(tree, vencode=lambda v: '%d' % v):
assert isinstance(tree, Tree)
topo = ''
# vdecode to be used in the verification at the end
vencoded = {} # vencode(vobj) -> vobj
def vdecode(vtxt):
return vencoded[vtxt]
# breadth-first traversal of the tree with '/' injected in between layers
for nodev in _walkBFS(tree):
if len(topo) != 0:
......@@ -803,6 +808,7 @@ def TopoEncode(tree, vencode=lambda v: '%d' % v):
assert ',' not in vtxt
assert '-' not in vtxt
vtxtv.append(vtxt)
vencoded[vtxt] = v
tnode += ','.join(['%d:%s' % (k,vtxt)
for (k,vtxt) in zip(node.keyv, vtxtv)])
else:
......@@ -813,7 +819,7 @@ def TopoEncode(tree, vencode=lambda v: '%d' % v):
topo += '-'.join(tnodev)
if 1: # make sure that every topology we emit, can be loaded back
t2 = TopoDecode(topo)
t2 = TopoDecode(topo, vdecode)
if t2 != tree:
panic("BUG: TopoEncode: D(E(·)) != identity\n· = %s\n D(E(·) = %s" % (tree, t2))
return topo
......
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