Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
wendelin.core
Commits
7a436584
Commit
7a436584
authored
May 21, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
9c2e028e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
9 deletions
+48
-9
wcfs/testprog/treedelta-genallstructs.py
wcfs/testprog/treedelta-genallstructs.py
+48
-9
No files found.
wcfs/testprog/treedelta-genallstructs.py
View file @
7a436584
...
...
@@ -45,8 +45,10 @@ from __future__ import print_function, absolute_import
import
sys
from
golang
import
func
,
defer
from
golang
import
time
from
ZODB
import
DB
import
transaction
import
random
from
wendelin.wcfs.internal
import
xbtree
from
wendelin.bigfile.file_zodb
import
ZBlk
...
...
@@ -75,6 +77,31 @@ def kvDecode(kvText, vdecode): # -> kvDict
kv
[
k
]
=
v
return
kv
# diff computes difference in between mappings d1 and d2.
DEL
=
'ø'
def
diff
(
d1
,
d2
):
# -> [] of (k,v) to change; DEL means del[k]
# patch changes mapping d according to diff.
# diff = [] of (k,v) to change; DEL means del[k]
def
patch
(
d
,
diff
,
verify
):
for
(
k
,
v
)
in
diff
:
if
v
is
DEL
:
del
d
[
k
]
else
:
d
[
k
]
=
v
if
verify
is
None
:
return
keys
=
set
(
d
.
keys
())
keyok
=
set
(
verify
.
keys
())
if
keys
!=
keyok
:
panic
(
"patch: verify: different keys: %s"
%
keys
.
symmetric_difference
(
keyok
))
for
k
in
keys
:
if
d
[
k
]
is
not
verify
[
k
]:
panic
(
"patch: verify: [%d] different: got %r; want %r"
%
(
k
,
d
[
k
],
verify
[
k
]))
# XXX
#
# kv: k₁:v₁,k₂:v₂,...
...
...
@@ -111,8 +138,8 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n):
kv1
=
kvDecode
(
kv1txt
,
vdecode
)
kv2
=
kvDecode
(
kv2txt
,
vdecode
)
diff12
=
[]
# of (k,v) diff to go from kv1 to kv2 XXX compute
diff21
=
[]
# of (k,v) diff to go from kv2 to kv1
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
maxdepth
=
2
# XXX -> 3?
maxsplit
=
1
# XXX -> 2?
...
...
@@ -128,11 +155,7 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n):
t1struct0
=
xbtree
.
StructureOf
(
ztree
)
# emit initial kv2 state prepared as ZODB would natively
for
(
k
,
v
)
in
diff12
:
if
v
is
DEL
:
del
ztree
[
k
]
else
:
ztree
[
k
]
=
v
patch
(
ztree
,
diff12
,
verify
=
kv2
)
transaction
.
commit
()
# XXX printδ
t2struct0
=
xbtree
.
StructureOf
(
ztree
)
...
...
@@ -142,8 +165,24 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n):
t2structv
=
[
t2struct0
]
+
random
.
sample
(
t2AllStructs
,
n
)
# emit tree1->tree2 and tree1<-tree2 transitions for all combinations of tree1 and tree2.
# tree1₀->tree2₀ was already emitted.
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δ
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment