Commit 8d90dfb2 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 70da0a60
...@@ -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 understanding 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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment