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
fdcec437
Commit
fdcec437
authored
May 22, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
aecd4dfd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
30 deletions
+26
-30
wcfs/testprog/treedelta-genallstructs.py
wcfs/testprog/treedelta-genallstructs.py
+26
-30
No files found.
wcfs/testprog/treedelta-genallstructs.py
View file @
fdcec437
...
...
@@ -96,7 +96,6 @@ def diff(d1, d2): # -> [] of (k,v) to change; DEL means del[k]
delta
.
append
((
k
,
v2
))
return
delta
# patch changes mapping d according to diff.
# diff = [] of (k,v) to change; DEL means del[k]
def
patch
(
d
,
diff
,
verify
):
...
...
@@ -145,16 +144,15 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n):
zconn
=
db
.
open
();
defer
(
zconn
.
close
)
root
=
zconn
.
root
()
# seed
seed
=
int
(
time
.
now
())
print
(
"# seed=%d"
%
seed
)
random
.
seed
(
seed
)
# root['treedelta/values'] = {} v -> ZBlk(v)
valdict
=
root
[
'treedelta/values'
]
=
PersistentMapping
()
valv
=
b'abcdefghi'
for
v
in
valv
:
# XXX don't ovewrite if already set?
zblk
=
ZBlk
()
zblk
.
setblkdata
(
v
)
valdict
[
v
]
=
zblk
...
...
@@ -173,30 +171,40 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n):
kv1
=
kvDecode
(
kv1txt
,
vdecode
)
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
# all topology structs that can represent kv1 and kv2
maxdepth
=
2
# XXX -> 3?
maxsplit
=
1
# XXX -> 2?
t1AllStructs
=
list
(
xbtree
.
AllStructs
(
kv1
.
keys
(),
maxdepth
,
maxsplit
))
t2AllStructs
=
list
(
xbtree
.
AllStructs
(
kv2
.
keys
(),
maxdepth
,
maxsplit
))
#
emit initial kv1 state prepared as ZODB would natively
ztree
=
root
[
'treedelta/tree'
]
=
BTrees
.
LOBTree
.
LOBTree
()
# XXX -> XLOTree (small nodes)
#
create the tree
ztree
=
root
[
'treedelta/tree'
]
=
BTrees
.
LOBTree
.
LOBTree
()
# XXX -> XLOTree (small nodes)
commit
(
'treedelta/tree'
)
for
k
in
sorted
(
kv1
):
ztree
[
k
]
=
kv1
[
k
]
ttxt
=
treetxt
(
ztree
)
tid
=
commit
(
ttxt
)
# XXX print txnδ
t1struct0
=
xbtree
.
StructureOf
(
ztree
)
# XXX print something?
# emit patches ztree with delta, adjusts tree structure and emits corresponding commit.
def
emit
(
delta
,
verify
,
treeTopo
):
ttxt_prev
=
treetxt
(
ztree
)
patch
(
ztree
,
delta
,
verify
)
if
treeTopo
is
not
None
:
xbtree
.
Restructure
(
ztree
,
treeTopo
)
ttxt
=
treetxt
(
ztree
)
tid
=
commit
(
'%s -> %s'
%
(
ttxt_prev
,
ttxt
))
print
(
'txn %s # %s -> %s'
%
(
ashex
(
tid
),
ttxt_prev
,
ttxt
))
for
(
k
,
v
)
in
delta
:
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) ?
# emit initial kv2 state prepared as ZODB would natively
patch
(
ztree
,
diff12
,
verify
=
kv2
)
ttxt_prev
=
ttxt
ttxt
=
treetxt
(
ztree
)
tid
=
commit
(
'%s -> %s'
%
(
ttxt_prev
,
ttxt
))
# XXX printδ
# emit initial kv1 and kv2 states prepared as ZODB would do natively
emit
(
diff
({},
kv1
),
verify
=
kv1
,
treeTopo
=
None
)
t1struct0
=
xbtree
.
StructureOf
(
ztree
)
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
...
...
@@ -218,19 +226,7 @@ def treedeltaGenAllStructs(zstor, kv1txt, kv2txt, n):
verify
=
kv2
assert
tstruct
in
t2structv
patch
(
ztree
,
delta
,
verify
)
xbtree
.
Restructure
(
ztree
,
tstruct
)
ttxt_prev
=
ttxt
ttxt
=
treetxt
(
ztree
)
tid
=
commit
(
'%s -> %s'
%
(
ttxt_prev
,
ttxt
))
print
(
'txn %s # %s -> %s'
%
(
ashex
(
tid
),
ttxt_prev
,
ttxt
))
for
(
k
,
v
)
in
delta
:
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) ?
emit
(
delta
,
verify
,
tstruct
)
# bitravel2Way generates travel path through all A<->B edges such
...
...
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