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
8d90dfb2
Commit
8d90dfb2
authored
Jun 05, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
70da0a60
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
10 deletions
+11
-10
wcfs/internal/xbtree.py
wcfs/internal/xbtree.py
+11
-10
No files found.
wcfs/internal/xbtree.py
View file @
8d90dfb2
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
"""Package xbtree provides utilities for inspecting/manipulating internal
"""Package xbtree provides utilities for inspecting/manipulating internal
structure of integer-keyed BTrees.
structure of integer-keyed BTrees.
It is primarily used to verify ΔBTail in wcfs.
It is primarily used to
help
verify ΔBTail in wcfs.
- `Tree` represents a tree node.
- `Tree` represents a tree node.
- `Bucket` represents a bucket node.
- `Bucket` represents a bucket node.
...
@@ -91,7 +91,7 @@ in left-to-right order.
...
@@ -91,7 +91,7 @@ in left-to-right order.
Visualization
Visualization
-------------
-------------
The following visualization utilities are provided to help understand
ing
BTrees
The following visualization utilities are provided to help understand BTrees
better:
better:
- `topoview` displays BTree structure given its topology-encoded representation.
- `topoview` displays BTree structure given its topology-encoded representation.
...
@@ -158,7 +158,6 @@ class Tree(object):
...
@@ -158,7 +158,6 @@ class Tree(object):
return
s
return
s
__repr__
=
__str__
__repr__
=
__str__
# copy returns a deep copy of the tree.
# copy returns a deep copy of the tree.
# if onlyKeys=Y buckets in returned tree will contain only keys not values.
# if onlyKeys=Y buckets in returned tree will contain only keys not values.
def
copy
(
t
,
onlyKeys
=
False
):
def
copy
(
t
,
onlyKeys
=
False
):
...
@@ -285,7 +284,7 @@ def Restructure(ztree, newStructure):
...
@@ -285,7 +284,7 @@ def Restructure(ztree, newStructure):
zcheck
(
ztree
)
# verify ztree before our tweaks
zcheck
(
ztree
)
# verify ztree before our tweaks
#
dict
with all k->v from ztree
#
{}
with all k->v from ztree
kv
=
dict
(
ztree
)
kv
=
dict
(
ztree
)
# walk original and new structures level by level.
# walk original and new structures level by level.
...
@@ -333,7 +332,6 @@ def Restructure(ztree, newStructure):
...
@@ -333,7 +332,6 @@ def Restructure(ztree, newStructure):
assert
abs
(
v
)
<
1E3
assert
abs
(
v
)
<
1E3
return
v
return
v
def
d2
(
x
,
y
):
def
d2
(
x
,
y
):
#return abs(fin(x)-fin(y))
return
(
fin
(
x
)
-
fin
(
y
))
**
2
return
(
fin
(
x
)
-
fin
(
y
))
**
2
return
d2
(
a
.
range
.
klo
,
b
.
range
.
klo
)
+
\
return
d2
(
a
.
range
.
klo
,
b
.
range
.
klo
)
+
\
d2
(
a
.
range
.
khi
,
b
.
range
.
khi
)
d2
(
a
.
range
.
khi
,
b
.
range
.
khi
)
...
@@ -349,8 +347,8 @@ def Restructure(ztree, newStructure):
...
@@ -349,8 +347,8 @@ def Restructure(ztree, newStructure):
# find the assignments.
# find the assignments.
# TODO try to avoid scipy dependency; we could also probably make
# TODO try to avoid scipy dependency; we could also probably make
# 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
is so that if B2 > B1 (all keys
# B2 > all keys in B1) and A < B1.hi, then D(B2, A) > D(B1, A).
#
in
B2 > all keys in B1) and A < B1.hi, then D(B2, A) > D(B1, A).
jv
,
iv
=
scipy
.
optimize
.
linear_sum_assignment
(
C
)
jv
,
iv
=
scipy
.
optimize
.
linear_sum_assignment
(
C
)
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
...
@@ -381,7 +379,7 @@ def Restructure(ztree, newStructure):
...
@@ -381,7 +379,7 @@ def Restructure(ztree, newStructure):
zrlevelv
=
list
(
__zwalkBFS
(
ztree
))
# [] of _NodeInRange
zrlevelv
=
list
(
__zwalkBFS
(
ztree
))
# [] of _NodeInRange
rlevelv
=
list
(
__walkBFS
(
tnew
))
# [] of _NodeInRange
rlevelv
=
list
(
__walkBFS
(
tnew
))
# [] of _NodeInRange
# associate every non-bucket node in tnew to a znode
# associate every non-bucket node in tnew to a znode
,
# extract bucket nodes.
# extract bucket nodes.
zrbucketv
=
[]
# of _NodeInRange
zrbucketv
=
[]
# of _NodeInRange
rbucketv
=
[]
# of _NodeInRange
rbucketv
=
[]
# of _NodeInRange
...
@@ -818,7 +816,10 @@ def TopoEncode(tree, vencode=lambda v: '%d' % v):
...
@@ -818,7 +816,10 @@ def TopoEncode(tree, vencode=lambda v: '%d' % v):
assert
','
not
in
vtxt
assert
','
not
in
vtxt
assert
'-'
not
in
vtxt
assert
'-'
not
in
vtxt
vtxtv
.
append
(
vtxt
)
vtxtv
.
append
(
vtxt
)
vencoded
[
vtxt
]
=
v
if
vtxt
in
vencoded
:
assert
vencoded
[
vtxt
]
==
v
else
:
vencoded
[
vtxt
]
=
v
tnode
+=
','
.
join
([
'%d:%s'
%
(
k
,
vtxt
)
tnode
+=
','
.
join
([
'%d:%s'
%
(
k
,
vtxt
)
for
(
k
,
vtxt
)
in
zip
(
node
.
keyv
,
vtxtv
)])
for
(
k
,
vtxt
)
in
zip
(
node
.
keyv
,
vtxtv
)])
else
:
else
:
...
@@ -843,7 +844,7 @@ class TopoDecodeError(Exception):
...
@@ -843,7 +844,7 @@ class TopoDecodeError(Exception):
pass
pass
def
TopoDecode
(
text
,
vdecode
=
int
):
def
TopoDecode
(
text
,
vdecode
=
int
):
levelv
=
text
.
split
(
'/'
)
# T3/T-T/B1:a-T5/B-B7,8,9 -> T3 T-T B1:a-T5 B-B7,8,9
levelv
=
text
.
split
(
'/'
)
# T3/T-T/B1:a-T5/B-B7,8,9 -> T3 T-T B1:a-T5 B-B7,8,9
#
XXX forbid mixing buckets-with-value with buckets-without-value?
#
NOTE we don't forbid mixing buckets-with-value with buckets-without-value
# build nodes from bottom-up
# build nodes from bottom-up
currentv
=
[]
# of nodes on current level (that we are building)
currentv
=
[]
# of nodes on current level (that we are building)
...
...
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