getAllTargets() public method

A list of all potential targets.
public getAllTargets ( ) : array
return array
Ejemplo n.º 1
0
 public function testRemoveTarget()
 {
     $hashSpace = new Flexihash();
     $hashSpace->addTarget('t-a')->addTarget('t-b')->addTarget('t-c')->removeTarget('t-b');
     $this->assertEquals($hashSpace->getAllTargets(), ['t-a', 't-c']);
 }
Ejemplo n.º 2
0
 public function testHashDistributionWithCrc32Hasher()
 {
     $hashSpace = new Flexihash(new Crc32Hasher());
     foreach (range(1, $this->_targets) as $i) {
         $hashSpace->addTarget("target{$i}");
     }
     $results = array();
     foreach (range(1, $this->_lookups) as $i) {
         $results[$i] = $hashSpace->lookup("t{$i}");
     }
     $distribution = array();
     foreach ($hashSpace->getAllTargets() as $target) {
         $distribution[$target] = count(array_keys($results, $target));
     }
     echo sprintf("\nDistribution of %d lookups per target (min/max/median/avg): %d/%d/%d/%d \n", $this->_lookups / $this->_targets, min($distribution), max($distribution), round($this->_median($distribution)), round(array_sum($distribution) / count($distribution)));
 }