Commit 70da0a60 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 11538410
......@@ -18,8 +18,6 @@
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
# XXX review
"""Package xbtree provides utilities for inspecting/manipulating internal
structure of integer-keyed BTrees.
......@@ -990,6 +988,7 @@ def graphviz(t, clustername=''):
assert isinstance(t, Tree)
symtab = {} # id(node) -> name
valtab = {} # value -> name
outv = []
def emit(text):
......@@ -1001,8 +1000,6 @@ def graphviz(t, clustername=''):
for (level, nodev) in enumerate(_walkBFS(t)):
for (i, node) in enumerate(nodev):
assert isinstance(node, (Tree,Bucket))
# TODO show Bucket values in triangles
# register node in symtab
assert id(node) not in symtab
kind = ('T' if isinstance(node, Tree) else 'B')
......@@ -1032,17 +1029,42 @@ def graphviz(t, clustername=''):
emit(' </table>>')
emit(' ]')
# second pass: emit links + node ranks
# emit values
if kind == 'B' and node.valuev is not None:
assert len(node.keyv) == len(node.valuev)
for (j,key) in enumerate(node.keyv):
v = node.valuev[j]
valtab[v] = '%sV%s' % (clustername+'_', v)
# second pass: emit links + node ranks + links to values
for nodev in _walkBFS(t):
# same rank for nodes on the same level
emit('')
emit(' {rank=same; %s}' % ' '.join([qq(symtab[id(_)]) for _ in nodev]))
# links
for node in nodev:
if not isinstance(node, Tree):
continue
for (j,child) in enumerate(node.children):
emit(' %s:"con%d" -> %s' % (qq(symtab[id(node)]), j, qq(symtab[id(child)])))
assert isinstance(node, (Tree,Bucket))
if isinstance(node, Tree):
for (j,child) in enumerate(node.children):
emit(' %s:"con%d" -> %s' % (qq(symtab[id(node)]), j, qq(symtab[id(child)])))
elif node.valuev is not None:
assert len(node.valuev) == len(node.keyv)
for (j,key) in enumerate(node.keyv):
emit(' %s:"key%d" -> %s' % (qq(symtab[id(node)]), j, valtab[node.valuev[j]]))
# third pass: emit values
emit('')
for v in sorted(valtab):
emit(' %s' % qq(valtab[v]))
emit(' [')
emit(' shape = plain')
emit(' label = "%s"' % v)
emit(' margin = 0')
emit(' height = 0')
emit(' width = 0')
emit(' ]')
#emit('}')
emit('')
......
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