Minor optimization in the HashRing class when adding/removing nodes from the ring

This commit is contained in:
Daniele Alessandri
2009-11-11 11:57:59 +01:00
parent 25d995942d
commit 7dde9ff93c
+4 -2
View File
@@ -679,8 +679,9 @@ class HashRing {
}
public function add($node) {
$nodeHash = (string) $node;
for ($i = 0; $i < self::NUMBER_OF_REPLICAS; $i++) {
$key = crc32((string)$node . ':' . $i);
$key = crc32($nodeHash . ':' . $i);
$this->_ring[$key] = $node;
}
ksort($this->_ring, SORT_NUMERIC);
@@ -688,8 +689,9 @@ class HashRing {
}
public function remove($node) {
$nodeHash = (string) $node;
for ($i = 0; $i < self::NUMBER_OF_REPLICAS; $i++) {
$key = crc32((string)$node . '_' . $i);
$key = crc32($nodeHash . '_' . $i);
unset($this->_ring[$key]);
$this->_ringKeys = array_filter($this->_ringKeys, function($rk) use($key) {
return $rk !== $key;