Update routing.py

This commit is contained in:
呆萌的弛哥SkyZH在银光闪烁的沙滩上面对大海写代码 2015-10-16 23:43:11 +08:00
parent 00ecaf5e31
commit a9e390126c

View File

@ -21,11 +21,11 @@ class KBucket(object):
return self.nodes.values() return self.nodes.values()
def split(self): def split(self):
midpoint = self.range[1] - ((self.range[1] - self.range[0]) / 2) midpoint = (self.range[0] + self.range[1]) / 2
one = KBucket(self.range[0], midpoint, self.ksize) one = KBucket(self.range[0], midpoint, self.ksize)
two = KBucket(midpoint + 1, self.range[1], self.ksize) two = KBucket(midpoint + 1, self.range[1], self.ksize)
for node in self.nodes.values(): for node in self.nodes.values():
bucket = one if node.long_id <= midpoint else two bucket = one if node.id <= midpoint else two
bucket.nodes[node.id] = node bucket.nodes[node.id] = node
return (one, two) return (one, two)