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

.

parent ba86a886
......@@ -148,7 +148,7 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n):
zblk = ZBlk()
zblk.setblkdata(v)
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)
# vencode(vobj) -> vtxt encodes value object into value text, e.g. ZBlk(a) -> 'a'
......@@ -176,16 +176,16 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n):
commit('treedelta/tree')
for k in sorted(kv1):
ztree[k] = kv1[k]
ztxt = treetxt(ztree)
commit(ztxt)
ttxt = treetxt(ztree)
commit(ttxt)
# XXX print txnδ
t1struct0 = xbtree.StructureOf(ztree)
# emit initial kv2 state prepared as ZODB would natively
patch(ztree, diff12, verify=kv2)
ztxt_prev = ztxt
ztxt = treetxt(ztree)
commit('%s -> %s' % (ztxt_prev, ztxt))
ttxt_prev = ttxt
ttxt = treetxt(ztree)
commit('%s -> %s' % (ttxt_prev, ttxt))
# XXX printδ
t2struct0 = xbtree.StructureOf(ztree)
......@@ -194,27 +194,54 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n):
t2structv = [t2struct0] + random.sample(t2AllStructs, min(n, len(t2AllStructs)))
# emit tree1->tree2 and tree1<-tree2 transitions for all combinations of tree1 and tree2.
for i in range(len(t1structv)):
for j in range(len(t2structv)):
tree1 = t1structv[i]
tree2 = t2structv[j]
# tree1->tree2
if not (i==0 and j==0):
# tree1₀->tree2₀ was already emitted while initializing.
patch(ztree, diff12, verify=kv2)
xbtree.Restructure(ztree, tree2)
transaction.commit()
# XXX printδ
# tree1<-tree2
patch(ztree, diff21, verify=kv1)
xbtree.Restructure(ztree, tree1)
transaction.commit()
# XXX printδ
# tree1₀->tree2₀ was already emitted.
t12travel = list(bitravel2Way(t1structv, t2structv))
assert t12travel[0] is t1struct0
assert t12travel[1] is t2struct0
for i,tstruct in enumerate(t12travel[2:]):
if i%2 == 0:
delta = diff21
verify = kv1
assert tstruct in t1structv
else:
delta = diff12
verify = kv2
assert tstruct in t2structv
patch(ztree, delta, verify)
xbtree.Restructure(ztree, tstruct)
ttxt_prev = ttxt
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
def main():
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