Commit 809304d1 authored by Kirill Smelkov's avatar Kirill Smelkov

X "B:" indicates ø bucket with k&b, "B" - ø bucket with only keys

parent 63dd361f
......@@ -187,7 +187,10 @@ class Bucket(object):
kvv = ['%s' % k for k in b.keyv]
else:
assert len(b.keyv) == len(b.valuev)
kvv = ['%s:%s' % (k,v) for (k,v) in zip(b.keyv, b.valuev)]
if len(b.keyv) == 0:
kvv = [':']
else:
kvv = ['%s:%s' % (k,v) for (k,v) in zip(b.keyv, b.valuev)]
return "B" + ','.join(kvv)
__repr__ = __str__
......@@ -762,16 +765,19 @@ def TopoEncode(tree, vencode=lambda v: '%d' % v):
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)])
assert len(node.keyv) == len(node.valuev)
if len(node.keyv) == 0:
tnode += ':'
else:
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])
......@@ -820,14 +826,15 @@ def TopoDecode(text, vdecode=int):
withV = (typ is Bucket and ':' in tkeys)
keyv = []
valuev= [] if withV else None
for tkey in tkeyv:
ktxt = tkey
if withV:
ktxt, vtxt = tkey.split(':')
v = vdecode(vtxt)
valuev.append(v)
k = int(ktxt)
keyv.append(k)
if tkeys != ':': # "B:" indicates ø bucket with values
for tkey in tkeyv:
ktxt = tkey
if withV:
ktxt, vtxt = tkey.split(':')
v = vdecode(vtxt)
valuev.append(v)
k = int(ktxt)
keyv.append(k)
if typ is Bucket:
node = Bucket(keyv, valuev)
......
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