* 删除节点 * @param $key */ public function remove_node($key) { $hash = $this->mHash($key); if (isset($this->_nodes[$hash])) { unset($this->_nodes[$hash]); } //重新排序 krsort($this->_nodes, SORT_NUMERIC); } /** * 获取节点 * @param $key * @return mixed */ public function get_node($key) { $hash = $this->mHash($key); foreach ($this->_nodes as $pos => $node) { if ($pos >= $hash) { return $node; } } return $this->_nodes[$pos]; } } $hash = new ConsistentHash(); echo dechex($hash->mHash("testA123")) . "\n";