Flexihash\Flexihash::removeTarget PHP Méthode

removeTarget() public méthode

Remove a target.
public removeTarget ( string $target ) : self
$target string
Résultat self fluent
    public function removeTarget($target)
    {
        if (!isset($this->targetToPositions[$target])) {
            throw new Exception("Target '{$target}' does not exist.");
        }
        foreach ($this->targetToPositions[$target] as $position) {
            unset($this->positionToTarget[$position]);
        }
        unset($this->targetToPositions[$target]);
        --$this->targetCount;
        return $this;
    }

Usage Example

Exemple #1
0
 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";
 }
All Usage Examples Of Flexihash\Flexihash::removeTarget