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