Commit bd345fba authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent edb4941e
......@@ -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)
......
......@@ -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],
......
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