Commit ceef9fba authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 9bd4feda
......@@ -64,12 +64,13 @@ import BTrees.LOBTree
#
# kv: k₁:v₁,k₂:v₂,...
@func
def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n):
def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n, seed=None):
db = DB(zstor); defer(db.close)
zconn = db.open(); defer(zconn.close)
root = zconn.root()
# seed
if seed is None:
seed = int(time.now())
print("# seed=%d" % seed)
random.seed(seed)
......@@ -97,10 +98,10 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n):
kv2 = kvDecode(kv2txt, vdecode)
# δ kv1 <-> kv2
diff12 = diff(kv1, kv2) # of (k,v) diff to go from kv1 to kv2
diff21 = diff(kv2, kv1) # of (k,v) diff to go from kv2 to kv1
diff12 = diff(kv1, kv2)
diff21 = diff(kv2, kv1)
# all topology structs that can represent kv1 and kv2
# all tree topologies that can represent kv1 and kv2
maxdepth=2 # XXX -> 3?
maxsplit=1 # XXX -> 2?
t1AllStructs = list(xbtree.AllStructs(kv1.keys(), maxdepth, maxsplit))
......@@ -124,7 +125,8 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n):
vtxt = 'ø'
if v is not DEL:
vtxt = vencode(v)
print('\t%d:%s' % (k,vtxt)) # XXX print not only +, but also - (e.g. -1:a +1:b) ?
# XXX print not only +, but also - (e.g. -1:a +1:b) ?
print('\t%d:%s' % (k,vtxt))
# emit initial kv1 and kv2 states prepared as ZODB would do natively
emit(diff({}, kv1), verify=kv1, treeTopo=None)
......@@ -132,12 +134,13 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n):
emit(diff(kv1, kv2), verify=kv2, treeTopo=None)
t2struct0 = xbtree.StructureOf(ztree)
# all tree1 and tree2 topologies we are going to emit: native + n random ones
# all tree1 and tree2 topologies jumps in between we are going to emit:
# native + n random ones.
t1structv = [t1struct0] + random.sample(t1AllStructs, min(n, len(t1AllStructs)))
t2structv = [t2struct0] + random.sample(t2AllStructs, min(n, len(t2AllStructs)))
# emit tree1->tree2 and tree1<-tree2 transitions for all combinations of tree1 and tree2.
# tree1₀->tree2₀ was already emitted.
# tree1₀->tree2₀ was already done.
t12travel = list(bitravel2Way(t1structv, t2structv))
assert t12travel[0] is t1struct0
assert t12travel[1] is t2struct0
......
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