public function getGroup(string $key) : int
{
$searchHash = self::generate_key_hash($key);
$begin = 0;
$end = count($this->_hashRingIds) - 1;
while ($begin <= $end) {
$pos = $begin + ($end - $begin >> 1);
$curVal = $this->_hashRingIds[$pos];
if ($searchHash > $curVal) {
$begin = $pos + 1;
} else {
$end = $pos - 1;
}
}
// Postcondition: $this->_hashRingIds[$begin] >= $searchHash, and $this->_hashRingIds[$begin - 1] does not exist or is less than $searchHash.
// Fetch the group corresponding to that hash in the hash ring.
return $this->_hashRingGroups[$begin];
}