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
448c5f4d
Commit
448c5f4d
authored
May 18, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
fc509e63
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
33 deletions
+27
-33
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+26
-33
wcfs/internal/xbtree_test.py
wcfs/internal/xbtree_test.py
+1
-0
No files found.
wcfs/internal/xbtree.py
View file @
448c5f4d
...
...
@@ -160,8 +160,6 @@ class Tree(object):
return
child0
.
firstbucket
()
# Bucket represents a bucket node.
class
Bucket
(
object
):
# .keyv () of keys
...
...
@@ -186,7 +184,7 @@ class Bucket(object):
return
Bucket
(
*
b
.
keyv
)
# StructureOf returns internal structure of a BTree.
# StructureOf returns internal structure of a
ZODB
BTree.
#
# The structure is represented as Tree and Bucket nodes.
def
StructureOf
(
znode
):
...
...
@@ -235,7 +233,7 @@ def Restructure(ztree, newStructure):
kv
=
dict
(
ztree
)
# walk original and new structures level by level.
#
XXX push buckets till the end
#
push buckets till the end, then
# for each level we have A1...An "old" nodes, and B1...Bm "new" nodes.
# if n == m - map A-B 1-to-1
# if n < m - we have to "insert" (m-n) new nodes
...
...
@@ -253,9 +251,10 @@ def Restructure(ztree, newStructure):
#
# sum min d(a,b) sum min d(a,b)
# a∈A b∈B b∈B a∈A
# D(A,B) = ────────────── + ────────────── XXX
# D(A,B) = ────────────── + ────────────── XXX
-> D(A,B) = |A.lo, B.lo| + |A.hi - B.hi|
# N(A) N(B)
#
# XXX ^^^ -> assignment problem
# we will modify nodes from new set:
# - node.Z will point to associated znode
...
...
@@ -278,6 +277,7 @@ def Restructure(ztree, newStructure):
assert
not
hasattr
(
rn
.
node
,
'Z'
)
rn
.
node
.
Z
=
None
# D(a,b)
def
D
(
a
,
b
):
def
fin
(
v
):
# TeX hack: inf = 10000
if
v
==
+
inf
:
return
+
1E4
...
...
@@ -289,7 +289,7 @@ def Restructure(ztree, newStructure):
return
d
(
a
.
range
.
klo
,
b
.
range
.
klo
)
+
\
d
(
a
.
range
.
khi
,
b
.
range
.
khi
)
#
prepare
cost matrix
# cost matrix
C
=
np
.
zeros
((
len
(
RNv
),
len
(
RZv
)))
for
j
in
range
(
len
(
RNv
)):
# "workers"
for
i
in
range
(
len
(
RZv
)):
# "jobs"
...
...
@@ -297,9 +297,9 @@ def Restructure(ztree, newStructure):
# find the assignments.
# TODO try to avoid scipy dependency; we could also probably make
# assignments more efficiently taking
that Av and Bv are key↑ and th
e
#
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).
# assignments more efficiently taking
into account that Av and Bv ar
e
#
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:')
...
...
@@ -342,33 +342,16 @@ def Restructure(ztree, newStructure):
rbucketv
=
[]
# of _NodeInRange
rlevelv_orig
=
copy
.
copy
(
rlevelv
)
while
len
(
rlevelv
)
>
0
or
len
(
zrlevelv
)
>
0
:
if
len
(
rlevelv
)
==
0
:
rlevel
=
[]
else
:
rlevel
=
rlevelv
.
pop
(
0
)
if
len
(
zrlevelv
)
==
0
:
zrlevel
=
[]
else
:
rlevel
=
[]
zrlevel
=
[]
if
len
(
rlevelv
)
>
0
:
rlevel
=
rlevelv
.
pop
(
0
)
if
len
(
zrlevelv
)
>
0
:
zrlevel
=
zrlevelv
.
pop
(
0
)
# filter-out buckets to be processed in the end
_
=
[]
# zrlevel -> zrlevel, zrbucketv
for
zrn
in
zrlevel
:
assert
isinstance
(
zrn
.
node
,
(
ztreeType
,
zbucketType
))
if
isinstance
(
zrn
.
node
,
zbucketType
):
zrbucketv
.
append
(
zrn
)
else
:
_
.
append
(
zrn
)
zrlevel
=
_
_
=
[]
# rlevel -> rlevel, rbucketv
for
rn
in
rlevel
:
assert
isinstance
(
rn
.
node
,
(
Tree
,
Bucket
))
if
isinstance
(
rn
.
node
,
Bucket
):
rbucketv
.
append
(
rn
)
else
:
_
.
append
(
rn
)
rlevel
=
_
zrbucketv
,
zrlevel
=
_filter2
(
zrlevel
,
lambda
zrn
:
isinstance
(
zrn
.
node
,
zbucketType
))
rbucketv
,
rlevel
=
_filter2
(
rlevel
,
lambda
rn
:
isinstance
(
rn
.
node
,
Bucket
))
if
len
(
rlevel
)
==
0
:
continue
...
...
@@ -808,6 +791,16 @@ def _indent(prefix, text): # -> text
text
=
'
\
n
'
.
join
(
textv
)
return
text
# _filter2(l,pred) = filter(l,pred), filter(l,!pred)
def
_filter2
(
l
,
pred
):
t
,
f
=
[],
[]
for
_
in
l
:
if
pred
(
_
):
t
.
append
(
_
)
else
:
f
.
append
(
_
)
return
t
,
f
# _assertIncv asserts that values of vector v are strictly ↑
def
_assertIncv
(
v
):
prev
=
-
inf
...
...
wcfs/internal/xbtree_test.py
View file @
448c5f4d
...
...
@@ -664,3 +664,4 @@ def test_iterSplitByN():
assert
X
(
0
,
5
,
3
)
==
(
[
0
,
1
,
2
,
3
,
5
],
[
0
,
1
,
2
,
4
,
5
],
[
0
,
1
,
3
,
4
,
5
],
[
0
,
2
,
3
,
4
,
5
]
)
assert
X
(
0
,
5
,
4
)
==
(
[
0
,
1
,
2
,
3
,
4
,
5
],
)
assert
X
(
0
,
5
,
5
)
==
()
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