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
2e1fb4d8
Commit
2e1fb4d8
authored
May 18, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
c4a7a252
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
19 deletions
+10
-19
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+3
-16
wcfs/internal/xbtree_test.py
wcfs/internal/xbtree_test.py
+7
-3
No files found.
wcfs/internal/xbtree.py
View file @
2e1fb4d8
...
@@ -221,13 +221,12 @@ def Restructure(ztree, newStructure):
...
@@ -221,13 +221,12 @@ def Restructure(ztree, newStructure):
_
=
_zclassify
(
ztree
)
_
=
_zclassify
(
ztree
)
assert
_
.
is_ztree
assert
_
.
is_ztree
assert
isinstance
(
newStructure
,
Tree
)
assert
isinstance
(
newStructure
,
Tree
)
print
(
'
\
n
Restructure %s ->
\
n
%s'
%
(
ztree
,
newStructure
))
#
print('\nRestructure %s ->\n%s' % (ztree, newStructure))
ztreeType
=
type
(
ztree
)
ztreeType
=
type
(
ztree
)
zbucketType
=
ztreeType
.
_bucket_type
zbucketType
=
ztreeType
.
_bucket_type
_zbcheck
(
ztree
)
# verify ztree before our tweaks
_zbcheck
(
ztree
)
# verify ztree before our tweaks
print
()
# dict with all k->v from ztree
# dict with all k->v from ztree
kv
=
dict
(
ztree
)
kv
=
dict
(
ztree
)
...
@@ -300,13 +299,7 @@ def Restructure(ztree, newStructure):
...
@@ -300,13 +299,7 @@ def Restructure(ztree, newStructure):
# assignments more efficiently taking into account that Av and Bv are
# assignments more efficiently taking into account that Av and Bv are
# key↑ and the property of D function so that if B2 > B1 (all keys in
# 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).
# 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
)
jv
,
iv
=
scipy
.
optimize
.
linear_sum_assignment
(
C
)
#print(jv, iv)
for
(
j
,
i
)
in
zip
(
jv
,
iv
):
for
(
j
,
i
)
in
zip
(
jv
,
iv
):
RNv
[
j
].
node
.
Z
=
RZv
[
i
].
node
RNv
[
j
].
node
.
Z
=
RZv
[
i
].
node
...
@@ -315,7 +308,6 @@ def Restructure(ztree, newStructure):
...
@@ -315,7 +308,6 @@ def Restructure(ztree, newStructure):
# to newly created Z nodes.
# to newly created Z nodes.
for
j2
in
range
(
len
(
RNv
)):
for
j2
in
range
(
len
(
RNv
)):
if
j2
not
in
jv
:
if
j2
not
in
jv
:
#print('\n\n\nXXX create new @%d\n\n\n' % j2)
n
=
RNv
[
j2
].
node
n
=
RNv
[
j2
].
node
assert
n
.
Z
is
None
assert
n
.
Z
is
None
assert
isinstance
(
n
,
(
Tree
,
Bucket
))
assert
isinstance
(
n
,
(
Tree
,
Bucket
))
...
@@ -443,7 +435,7 @@ def Restructure(ztree, newStructure):
...
@@ -443,7 +435,7 @@ def Restructure(ztree, newStructure):
zstate
=
(
zstate
,)
zstate
=
(
zstate
,)
# firstbucket
# firstbucket
print
(
' (firstbucket -> B %x)'
%
(
id
(
node
.
firstbucket
().
Z
),))
#
print(' (firstbucket -> B %x)' % (id(node.firstbucket().Z),))
zstate
+=
(
node
.
firstbucket
().
Z
,)
zstate
+=
(
node
.
firstbucket
().
Z
,)
# https://github.com/zopefoundation/BTrees/blob/4.5.0-1-gc8bf24e/BTrees/BucketTemplate.c#L1195
# https://github.com/zopefoundation/BTrees/blob/4.5.0-1-gc8bf24e/BTrees/BucketTemplate.c#L1195
...
@@ -455,9 +447,8 @@ def Restructure(ztree, newStructure):
...
@@ -455,9 +447,8 @@ def Restructure(ztree, newStructure):
if
node
.
next_bucket
is
not
None
:
# next
if
node
.
next_bucket
is
not
None
:
# next
zstate
+=
(
node
.
next_bucket
.
Z
,)
zstate
+=
(
node
.
next_bucket
.
Z
,)
print
(
'B %x -> %x'
%
(
id
(
node
.
Z
),
id
(
node
.
next_bucket
.
Z
)))
print
(
'%s %x: ZSTATE: %r'
%
(
'T'
if
_zclassify
(
node
.
Z
).
is_ztree
else
'B'
,
id
(
node
.
Z
),
zstate
,))
#
print('%s %x: ZSTATE: %r' % ('T' if _zclassify(node.Z).is_ztree else 'B', id(node.Z), zstate,))
node
.
Z
.
__setstate__
(
zstate
)
node
.
Z
.
__setstate__
(
zstate
)
zstate2
=
node
.
Z
.
__getstate__
()
zstate2
=
node
.
Z
.
__getstate__
()
if
zstate2
!=
zstate
:
if
zstate2
!=
zstate
:
...
@@ -469,10 +460,6 @@ def Restructure(ztree, newStructure):
...
@@ -469,10 +460,6 @@ def Restructure(ztree, newStructure):
assert
tnew
.
Z
is
ztree
assert
tnew
.
Z
is
ztree
assert
len
(
kv
)
==
0
# all keys must have been popped
assert
len
(
kv
)
==
0
# all keys must have been popped
print
()
print
(
'new struct:'
)
print
(
StructureOf
(
ztree
))
print
()
_zbcheck
(
ztree
)
# verify ztree after our tweaks
_zbcheck
(
ztree
)
# verify ztree after our tweaks
tstruct
=
StructureOf
(
ztree
)
tstruct
=
StructureOf
(
ztree
)
if
tstruct
!=
newStructure
:
if
tstruct
!=
newStructure
:
...
...
wcfs/internal/xbtree_test.py
View file @
2e1fb4d8
...
@@ -494,7 +494,7 @@ def test_restructure():
...
@@ -494,7 +494,7 @@ def test_restructure():
assert
crack_btree
(
z
)
==
(
BTREE_EMPTY
,
[],
[])
assert
crack_btree
(
z
)
==
(
BTREE_EMPTY
,
[],
[])
return
z
return
z
# ---- tests ----
# ---- tests
with manual verification of resulting topology and nodes
----
# ø -> T/B
# ø -> T/B
z
=
Z0
()
z
=
Z0
()
...
@@ -671,9 +671,13 @@ def test_restructure():
...
@@ -671,9 +671,13 @@ def test_restructure():
assertB
(
b8
,
8
)
assertB
(
b8
,
8
)
# ---- tests on automatically generated topologies ----
#
# ( we make sure that Restructure can make the restructurement and that
# after restructure a tree remains valid without any error introduced )
#for nkeys in range(5):
for
nkeys
in
range
(
5
):
# XXX
#
pass
pass
def
test_walkBFS
():
def
test_walkBFS
():
...
...
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