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
ef6fb8db
Commit
ef6fb8db
authored
May 20, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
38dacb30
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
6 deletions
+23
-6
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+23
-6
No files found.
wcfs/internal/xbtree.py
View file @
ef6fb8db
...
...
@@ -89,7 +89,7 @@ better:
from
__future__
import
print_function
,
absolute_import
from
BTrees
import
check
as
zbcheck
from
golang
import
func
,
panic
from
golang
import
func
,
panic
,
defer
from
golang.gcompat
import
qq
import
itertools
import
re
...
...
@@ -216,12 +216,30 @@ def StructureOf(znode):
# topology structure.
#
# NOTE ZODB BTree package does not tolerate structures with empty BTree nodes
# except for the single case of empty tree.
# except for the sole single case of empty tree.
@
func
def
Restructure
(
ztree
,
newStructure
):
_
=
_zclassify
(
ztree
)
assert
_
.
is_ztree
assert
isinstance
(
newStructure
,
Tree
)
#print('\nRestructure %s ->\n%s' % (ztree, newStructure))
from_
=
TopoEncode
(
StructureOf
(
ztree
))
to_
=
TopoEncode
(
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
raise fmt.Errorf("Restructure %s -> %s: %w", from_, to_, exc)
defer(_)
"""
def
_
():
# XXX hack
exc
=
sys
.
exc_info
()[
1
]
if
exc
is
not
None
:
assert
len
(
exc
.
args
)
==
1
exc
.
args
=
(
"Restructure %s -> %s: %r"
%
(
from_
,
to_
,
exc
.
args
[
0
]),)
defer
(
_
)
ztreeType
=
type
(
ztree
)
zbucketType
=
ztreeType
.
_bucket_type
...
...
@@ -244,7 +262,7 @@ def Restructure(ztree, newStructure):
# - find solution to linear assignment problem A <- B with the cost given by D
# https://en.wikipedia.org/wiki/Assignment_problem
#
# D(A,B) = |A.lo
,
B.lo| + |A.hi - B.hi|
# D(A,B) = |A.lo
-
B.lo| + |A.hi - B.hi|
# we will modify nodes from new set:
# - node.Z will point to associated znode
...
...
@@ -312,8 +330,7 @@ def Restructure(ztree, newStructure):
# assert the result is 1-1 mapping
for
j
in
range
(
len
(
RNv
)):
if
RNv
[
j
].
node
.
Z
is
not
RZv
[
j
].
node
:
panic
(
"BUG: Restructure %s -> %s: assign: not 1-1 mapping:
\
n
RZv: %s
\
n
RNv: %s"
%
(
TopoEncode
(
StructureOf
(
ztree
)),
TopoEncode
(
newStructure
),
RZv
,
RNv
))
panic
(
"BUG: assign: not 1-1 mapping:
\
n
RZv: %s
\
n
RNv: %s"
%
(
RZv
,
RNv
))
# XXX assert assignments are in key↑ order ?
...
...
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