Commit 04f722ae authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent ba86a886
...@@ -148,7 +148,7 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n): ...@@ -148,7 +148,7 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n):
zblk = ZBlk() zblk = ZBlk()
zblk.setblkdata(v) zblk.setblkdata(v)
valdict[v] = zblk valdict[v] = zblk
commit('treedelta/values %s' % (list(valv),)) commit('treedelta/values %r' % valv)
# vdecode(vtxt) -> vobj decodes value text into value object, e.g. 'a' -> ZBlk(a) # vdecode(vtxt) -> vobj decodes value text into value object, e.g. 'a' -> ZBlk(a)
# vencode(vobj) -> vtxt encodes value object into value text, e.g. ZBlk(a) -> 'a' # vencode(vobj) -> vtxt encodes value object into value text, e.g. ZBlk(a) -> 'a'
...@@ -176,16 +176,16 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n): ...@@ -176,16 +176,16 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n):
commit('treedelta/tree') commit('treedelta/tree')
for k in sorted(kv1): for k in sorted(kv1):
ztree[k] = kv1[k] ztree[k] = kv1[k]
ztxt = treetxt(ztree) ttxt = treetxt(ztree)
commit(ztxt) commit(ttxt)
# XXX print txnδ # XXX print txnδ
t1struct0 = xbtree.StructureOf(ztree) t1struct0 = xbtree.StructureOf(ztree)
# emit initial kv2 state prepared as ZODB would natively # emit initial kv2 state prepared as ZODB would natively
patch(ztree, diff12, verify=kv2) patch(ztree, diff12, verify=kv2)
ztxt_prev = ztxt ttxt_prev = ttxt
ztxt = treetxt(ztree) ttxt = treetxt(ztree)
commit('%s -> %s' % (ztxt_prev, ztxt)) commit('%s -> %s' % (ttxt_prev, ttxt))
# XXX printδ # XXX printδ
t2struct0 = xbtree.StructureOf(ztree) t2struct0 = xbtree.StructureOf(ztree)
...@@ -194,27 +194,54 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n): ...@@ -194,27 +194,54 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n):
t2structv = [t2struct0] + random.sample(t2AllStructs, min(n, len(t2AllStructs))) t2structv = [t2struct0] + random.sample(t2AllStructs, min(n, len(t2AllStructs)))
# emit tree1->tree2 and tree1<-tree2 transitions for all combinations of tree1 and tree2. # emit tree1->tree2 and tree1<-tree2 transitions for all combinations of tree1 and tree2.
for i in range(len(t1structv)): # tree1₀->tree2₀ was already emitted.
for j in range(len(t2structv)): t12travel = list(bitravel2Way(t1structv, t2structv))
tree1 = t1structv[i] assert t12travel[0] is t1struct0
tree2 = t2structv[j] assert t12travel[1] is t2struct0
for i,tstruct in enumerate(t12travel[2:]):
# tree1->tree2 if i%2 == 0:
if not (i==0 and j==0): delta = diff21
# tree1₀->tree2₀ was already emitted while initializing. verify = kv1
patch(ztree, diff12, verify=kv2) assert tstruct in t1structv
xbtree.Restructure(ztree, tree2) else:
transaction.commit() delta = diff12
# XXX printδ verify = kv2
assert tstruct in t2structv
# tree1<-tree2
patch(ztree, diff21, verify=kv1) patch(ztree, delta, verify)
xbtree.Restructure(ztree, tree1) xbtree.Restructure(ztree, tstruct)
transaction.commit() ttxt_prev = ttxt
# XXX printδ ttxt = xbtree.TopoEncode(tstruct) # XXX with values
commit('%s -> %s' % (ttxt_prev, ttxt))
# XXX printδ
# bitravel2Way generates travel path through all A<->B edges such
# that all edges a->b and a<-b are traveled and exactly once.
#
# The travel starts from A[0].
def bitravel2Way(A, B): # -> i[] of node
na = len(A); assert na > 0
nb = len(B); assert nb > 0
yield A[0] # A₀
for j in range(nb):
yield B[j] # A₀ -> Bj
for i in range(1,na):
yield A[i] # Ai <- Bj
yield B[j] # Ai -> Bj
yield A[0] # A₀ <- Bj
def test_bitravel2Way():
a,b,c = 'a','b','c'
A = [a,b,c]
B = [1, 2]
assert list(bitravel2Way(A, B)) == [a,1,b,1,c,1,a,2,b,2,c,2,a,3,b,3,c,3,a]
test_bitravel2Way()
@func @func
def main(): def main():
if len(sys.argv) != 5: if len(sys.argv) != 5:
......
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