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
cdab1972
Commit
cdab1972
authored
May 12, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
8c550297
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
16 deletions
+29
-16
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+29
-16
No files found.
wcfs/internal/xbtree.py
View file @
cdab1972
...
...
@@ -240,6 +240,8 @@ def Restructure(ztree, newStructure):
# Bj ∈ RNv is mapped into Ai ∈ RZv such that that sum_j D(A_i, Bj) is minimal.
# it is used to associate nodes in tnew to ztree nodes.
def
assign
(
RZv
,
RNv
):
print
()
print
(
'assign %s <- %s'
%
(
RZv
,
RNv
))
for
rzn
in
RZv
:
assert
isinstance
(
rzn
,
_NodeInRange
)
assert
isinstance
(
rzn
.
node
,
(
ztreeType
,
zbucketType
))
...
...
@@ -268,8 +270,10 @@ def Restructure(ztree, newStructure):
# assignments more efficiently taking that Av and Bv are key↑ and the
# property of D function so that if B2 > B1 (all keys in B2 > all keys
# in B1) and A < B1.hi, then D(B2, A) > D(B1, A).
print
()
print
(
C
)
jv
,
iv
=
scipy
.
optimize
.
linear_sum_assignment
(
C
)
print
(
jv
,
iv
)
for
(
j
,
i
)
in
zip
(
jv
,
iv
):
RNv
[
j
].
node
.
Z
=
RZv
[
i
].
node
...
...
@@ -278,6 +282,7 @@ def Restructure(ztree, newStructure):
# to newly created Z nodes.
for
j2
in
range
(
len
(
RNv
)):
if
j2
not
in
jv
:
print
(
'
\
n
\
n
\
n
XXX create new @%d
\
n
\
n
\
n
'
%
j2
)
n
=
RNv
[
j2
].
node
assert
n
.
Z
is
None
assert
isinstance
(
n
,
(
Tree
,
Bucket
))
...
...
@@ -349,8 +354,10 @@ def Restructure(ztree, newStructure):
assert
len
(
rbucketv
)
>
0
for
i
in
range
(
len
(
rbucketv
)
-
1
):
assert
rbucketv
[
i
].
range
.
khi
<=
rbucketv
[
i
+
1
].
klo
rbucketv
[
i
].
node
.
next_bucket
=
rbucketv
[
i
+
1
].
node
rbucketv
[
i
]
.
node
.
next_bucket
=
rbucketv
[
i
+
1
].
node
rbucketv
[
i
+
1
].
node
.
prev_bucket
=
rbucketv
[
i
]
.
node
rbucketv
[
-
1
].
node
.
next_bucket
=
None
rbucketv
[
0
]
.
node
.
prev_bucket
=
None
# associate every bucket to zbucket
assign
(
zrbucketv
,
rbucketv
)
...
...
@@ -361,27 +368,33 @@ def Restructure(ztree, newStructure):
for
rnodev
in
rlevelv
:
for
rn
in
rnodev
:
node
=
rn
.
node
assert
isinstance
(
node
,
Tree
)
# buckets were filtered out to rbucketv
assert
isinstance
(
node
,
Tree
)
,
node
# buckets were filtered out to rbucketv
znode
=
node
.
Z
# https://github.com/zopefoundation/BTrees/blob/4.5.0-1-gc8bf24e/BTrees/BTreeTemplate.c#L1087
zstate
=
unset
=
object
()
if
len
(
node
.
keyv
)
==
0
:
child
=
node
.
children
[
0
]
if
isinstance
(
child
,
Bucket
):
if
len
(
child
.
keyv
)
==
0
:
panic
(
"TODO: empty tree"
)
if
child
.
Z
.
_p_oid
is
None
:
panic
(
"TODO: tree with bucket without oid"
)
zstate
=
()
assert
len
(
node
.
children
)
==
len
(
node
.
keyv
)
+
1
zstate
+=
node
.
children
[
0
]
for
(
child
,
k
)
in
zip
(
node
.
children
[
1
:],
node
.
keyv
):
zstate
+=
(
k
,
child
)
# (child0, k0, child1, k1, ..., childN, kN, childN+1)
zstate
=
(
zstate
,)
# firstbucket
zstate
+=
(
None
,)
# XXX
# empty bucket noone links to
if
len
(
child
.
keyv
)
==
0
and
child
.
prev_bucket
is
None
:
zstate
=
None
# -> empty tree
# tree with single bucket noone links to
elif
child
.
Z
.
_p_oid
is
None
and
child
.
prev_bucket
is
None
:
zstate
=
((
child
.
Z
.
__getstate__
(),),)
# tree with bucket without oid
if
zstate
is
unset
:
# normal tree node
zstate
=
()
assert
len
(
node
.
children
)
==
len
(
node
.
keyv
)
+
1
zstate
+=
node
.
children
[
0
]
for
(
child
,
k
)
in
zip
(
node
.
children
[
1
:],
node
.
keyv
):
zstate
+=
(
k
,
child
)
# (child0, k0, child1, k1, ..., childN, kN, childN+1)
zstate
=
(
zstate
,)
# firstbucket
zstate
+=
(
None
,)
# XXX
znode
.
__setstate__
(
zstate
)
...
...
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