Commit 126bbb7a authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 61eeb509
......@@ -59,7 +59,7 @@ A Tree is encoded by level-order traversal, delimiting layers with "/".
Inside a layer Tree and Bucket nodes are signalled as
"T<keys>" ; Tree
"B<keys>" ; Bucket
"B<keys>" ; Bucket XXX values
Keys are represented as ","-delimited list of integers. For example Tree
with [1,3,5] keys is represented as
......@@ -192,13 +192,16 @@ def StructureOf(znode):
ztype = _zclassify(znode)
if ztype.is_zbucket:
keys, _ = zbcheck.crack_bucket(znode, ztype.is_map)
return Bucket(*keys)
keys, values = zbcheck.crack_bucket(znode, ztype.is_map)
if not ztype.is_map:
return Bucket(*keys)
else:
return Bucket(keys, values) # XXX
if ztype.is_ztree:
kind, keys, children = zbcheck.crack_btree(znode, ztype.is_map)
if kind == zbcheck.BTREE_EMPTY:
return Tree([], Bucket())
return Tree([], Bucket()) # XXX values !None for map
if kind == zbcheck.BTREE_ONE:
b = znode._bucket_type()
......@@ -455,6 +458,7 @@ def Restructure(ztree, newStructure):
# https://github.com/zopefoundation/BTrees/blob/4.5.0-1-gc8bf24e/BTrees/BucketTemplate.c#L1195
if isinstance(node, Bucket):
# XXX assert that node.values is None or == kv[k] for k in node
zstate = ()
for k in node.keyv:
zstate += (k, kv.pop(k)) # (k1, v1, k2, v2, ..., kN, vN)
......@@ -508,7 +512,7 @@ def AllStructs(keys, maxdepth, maxsplit, allowEmptyBuckets=False): # -> i[] of T
else:
# the only possible case for empty tree is T/B
if not allowEmptyBuckets:
yield Tree([], Bucket())
yield Tree([], Bucket()) # XXX -> !values
return
# XXX ok? (ideally should be -inf,+inf)
......@@ -545,7 +549,7 @@ def _allStructs(klo, khi, keyv, maxdepth, maxsplit, allowEmptyBuckets):
bkeyv = _keyvSliceBy(keyv, xlo, xhi)
if not allowEmptyBuckets:
assert len(bkeyv) > 0
children.append(Bucket(*bkeyv))
children.append(Bucket(*bkeyv)) # XXX -> !values
else:
yield Tree(ksplitv[1:-1], *children) # (s1, s2, ..., sN)
......@@ -730,8 +734,9 @@ def __zwalkBFS(ztree): # i[] of [](of _NodeInRange on each level)
# TopoEncode returns topology encoding for internal structure of the tree.
#
# Vencode specifies way to encode values referred-to by buckets.
# See top-level docstring for description of topology encoding.
def TopoEncode(tree, vencode=lambda v: '%d' % v): # XXX vencode document
def TopoEncode(tree, vencode=lambda v: '%d' % v):
assert isinstance(tree, Tree)
topo = ''
......@@ -771,10 +776,11 @@ def TopoEncode(tree, vencode=lambda v: '%d' % v): # XXX vencode document
# TopoDecode decodes topology-encoded text into Tree structure.
#
# Vdecode specifies way to decode values referred-to by buckets.
# See top-level docstring for description of topology encoding.
class TopoDecodeError(Exception):
pass
def TopoDecode(text, vdecode=int): # XXX vdecode - document
def TopoDecode(text, vdecode=int):
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?
......@@ -930,6 +936,7 @@ 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
# register node in symtab
assert id(node) not in symtab
......
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