public function testHopeRemovingTargetDoesNotChangeMuchWithCrc32Hasher()
{
$hashSpace = new Flexihash(new Crc32Hasher());
foreach (range(1, $this->_targets) as $i) {
$hashSpace->addTarget("target{$i}");
}
$results1 = array();
foreach (range(1, $this->_lookups) as $i) {
$results1[$i] = $hashSpace->lookup("t{$i}");
}
$hashSpace->removeTarget("target1");
$results2 = array();
foreach (range(1, $this->_lookups) as $i) {
$results2[$i] = $hashSpace->lookup("t{$i}");
}
$differences = 0;
foreach (range(1, $this->_lookups) as $i) {
if ($results1[$i] !== $results2[$i]) {
$differences++;
}
}
$percent = round($differences / $this->_lookups * 100);
$this->assertEquals(9.0, $percent);
echo "\nConsistentHash: {$percent}% of lookups changed " . "after removing 1 of {$this->_targets} targets\n";
}