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
80f0e5eb
Commit
80f0e5eb
authored
May 25, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
87bcad49
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
7 deletions
+14
-7
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+14
-7
No files found.
wcfs/internal/xbtree.py
View file @
80f0e5eb
...
...
@@ -177,7 +177,7 @@ class Tree(object):
class
Bucket
(
object
):
# .keyv () of keys
# .valuev None | () of values len(.valuev) == len(.keyv)
def
__init__
(
b
,
keyv
,
valuev
):
# XXX syntax sugar for values? (lack of values)?
def
__init__
(
b
,
keyv
,
valuev
):
_assertIncv
(
keyv
)
b
.
keyv
=
tuple
(
keyv
)
if
valuev
is
None
:
...
...
@@ -249,7 +249,7 @@ def StructureOf(znode, onlyKeys=False):
# Restructure reorganizes ZODB BTree instance (not Tree) according to specified
# topology structure.
#
# The new structure should be given with
buckets without values. XXX should -> can?
# The new structure should be given with
key-only buckets.
#
# NOTE ZODB BTree package does not tolerate structures with empty BTree nodes
# except for the sole single case of empty tree.
...
...
@@ -265,7 +265,7 @@ def Restructure(ztree, newStructure):
def _():
exc = recover() # FIXME for panic - returns unwrapped arg, not PanicError
if exc is not None:
# FIXME %w creates only .Unwrap link, not with .__cause__
-> fix
# FIXME %w creates only .Unwrap link, not with .__cause__
raise fmt.Errorf("Restructure %s -> %s: %w", from_, to_, exc)
defer(_)
"""
...
...
@@ -304,7 +304,7 @@ def Restructure(ztree, newStructure):
# we will modify nodes from new set:
# - node.Z will point to associated znode
# - bucket.next_bucket will point to bucket that is coming with next keys in the tree
tnew
=
newStructure
.
copy
()
# XXX onlyKeys=True ?
tnew
=
newStructure
.
copy
()
# assign assigns tree nodes from RNv to ztree nodes from RZv in optimal way.
# Bj ∈ RNv is mapped into Ai ∈ RZv such that that sum_j D(A_i, Bj) is minimal.
...
...
@@ -490,7 +490,14 @@ def Restructure(ztree, newStructure):
# https://github.com/zopefoundation/BTrees/blob/4.5.0-1-gc8bf24e/BTrees/BucketTemplate.c#L1195
if
isinstance
(
node
,
Bucket
):
# XXX assert that node.values is None or == kv[k] for k in node
# if Bucket was specified with values - verify k->v do not
# change from what was in original tree.
if
node
.
valuev
is
not
None
:
assert
len
(
node
.
keyv
)
==
len
(
node
.
valuev
)
for
(
k
,
v
)
in
zip
(
node
.
keyv
,
node
.
valuev
):
if
kv
[
k
]
is
not
v
:
raise
ValueError
(
"target bucket changes [%d] %r -> %r"
,
k
,
kv
[
k
],
v
)
zstate
=
()
for
k
in
node
.
keyv
:
zstate
+=
(
k
,
kv
.
pop
(
k
))
# (k1, v1, k2, v2, ..., kN, vN)
...
...
@@ -503,7 +510,7 @@ def Restructure(ztree, newStructure):
node
.
Z
.
__setstate__
(
zstate
)
zstate2
=
node
.
Z
.
__getstate__
()
if
zstate2
!=
zstate
:
panic
(
"BUG:
Restructure:
node.__getstate__ returns not what "
panic
(
"BUG: node.__getstate__ returns not what "
"we passed into node.__setstate__.
\
n
node: %r
\
n
"
"__setstate__ <- %r
\
n
__getstate__ -> %r"
%
(
node
.
Z
,
zstate
,
zstate2
))
...
...
@@ -514,7 +521,7 @@ def Restructure(ztree, newStructure):
_zbcheck
(
ztree
)
# verify ztree after our tweaks
tstruct
=
StructureOf
(
ztree
,
onlyKeys
=
True
)
if
tstruct
!=
newStructure
:
panic
(
"BUG:
Restructure:
result structure is not what was"
panic
(
"BUG: result structure is not what was"
" requested:
\
n
%s
\
n
\
n
want:
\
n
%s"
%
(
tstruct
,
newStructure
))
...
...
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