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
0fed1216
Commit
0fed1216
authored
May 14, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
37a49cf8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
20 deletions
+29
-20
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+29
-20
No files found.
wcfs/internal/xbtree.py
View file @
0fed1216
...
...
@@ -220,11 +220,13 @@ def Restructure(ztree, newStructure):
_
=
_zclassify
(
ztree
)
assert
_
.
is_ztree
assert
isinstance
(
newStructure
,
Tree
)
print
(
'
\
n
Restructure %s ->
\
n
%s'
%
(
ztree
,
newStructure
))
ztreeType
=
type
(
ztree
)
zbucketType
=
ztreeType
.
_bucket_type
_bcheck
(
ztree
)
# verify ztree before our tweaks
print
()
# dict with all k->v from ztree
kv
=
dict
(
ztree
)
...
...
@@ -261,8 +263,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
))
#
print()
#
print('assign %s <- %s' % (RZv, RNv))
for
rzn
in
RZv
:
assert
isinstance
(
rzn
,
_NodeInRange
)
assert
isinstance
(
rzn
.
node
,
(
ztreeType
,
zbucketType
))
...
...
@@ -295,11 +297,13 @@ 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('COST:')
print(C)
"""
jv
,
iv
=
scipy
.
optimize
.
linear_sum_assignment
(
C
)
print
(
jv
,
iv
)
#
print(jv, iv)
for
(
j
,
i
)
in
zip
(
jv
,
iv
):
RNv
[
j
].
node
.
Z
=
RZv
[
i
].
node
...
...
@@ -308,7 +312,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
)
#
print('\n\n\nXXX create new @%d\n\n\n' % j2)
n
=
RNv
[
j2
].
node
assert
n
.
Z
is
None
assert
isinstance
(
n
,
(
Tree
,
Bucket
))
...
...
@@ -451,6 +455,7 @@ def Restructure(ztree, newStructure):
zstate
=
(
zstate
,)
# firstbucket
print
(
' (firstbucket -> B %x)'
%
(
id
(
node
.
firstbucket
().
Z
),))
zstate
+=
(
node
.
firstbucket
().
Z
,)
# https://github.com/zopefoundation/BTrees/blob/4.5.0-1-gc8bf24e/BTrees/BucketTemplate.c#L1195
...
...
@@ -462,8 +467,9 @@ def Restructure(ztree, newStructure):
if
node
.
next_bucket
is
not
None
:
# next
zstate
+=
(
node
.
next_bucket
.
Z
,)
print
(
'B %x -> %x'
%
(
id
(
node
.
Z
),
id
(
node
.
next_bucket
.
Z
)))
print
(
'
ZSTATE:'
,
zstate
)
print
(
'
%s %x: ZSTATE: %r'
%
(
'T'
if
_zclassify
(
node
.
Z
).
is_ztree
else
'B'
,
id
(
node
.
Z
),
zstate
,)
)
node
.
Z
.
__setstate__
(
zstate
)
zstate2
=
node
.
Z
.
__getstate__
()
if
zstate2
!=
zstate
:
...
...
@@ -822,23 +828,26 @@ def _zclassify(znode): # -> _ZNodeType
# _bcheck performs full consistency checks on ztree provided by ZODB.
#
# The checks are what is provided by BTree.check and node._check().
class
_ZChecker
(
zbcheck
.
Checker
):
def
visit_btree
(
self
,
obj
,
*
argv
):
#super(_ZChecker, self).visit_btree(obj, *argv) zbcheck.Checker is old-style class
zbcheck
.
Checker
.
visit_btree
(
self
,
obj
,
*
argv
)
obj
.
_check
()
# also check internal C-level pointers consistency
# no need to amend visit_bucket - there is no Bucket._check
"""
def visit_bucket(self, obj, *argv):
#super(_ZChecker, self).visit_bucket(obj, *argv)
zbcheck.Checker.visit_bucket(self, obj, *argv)
obj._check() # ----//-----
"""
#class _ZChecker(zbcheck.Checker):
# def visit_btree(self, obj, *argv):
# #super(_ZChecker, self).visit_btree(obj, *argv) zbcheck.Checker is old-style class
# zbcheck.Checker.visit_btree(self, obj, *argv)
# obj._check() # also check internal C-level pointers consistency
#
# # no need to amend visit_bucket - there is no Bucket._check
# """
# def visit_bucket(self, obj, *argv):
# #super(_ZChecker, self).visit_bucket(obj, *argv)
# zbcheck.Checker.visit_bucket(self, obj, *argv)
# obj._check() # ----//-----
# """
def
_bcheck
(
ztree
):
_ZChecker
(
ztree
).
check
()
zbcheck
.
check
(
ztree
)
#_ZChecker(ztree).check()
# verify internal C-level pointers consistency (valid to call only on root node)
ztree
.
_check
()
zbcheck
.
check
(
ztree
)
# verify nodes values consistency
...
...
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