X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2FHashRing.php;h=3b9c24d978ab133119b316d1470490bd33d24e03;hb=6a830879a594653842dd623c4fa36559e346cc5d;hp=be40965e8414a651880f58ffe37ae75fdc3d4dbe;hpb=03cd9495a4dac1c1cda738d52e74b553b977beb8;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/HashRing.php b/includes/libs/HashRing.php index be40965e84..3b9c24d978 100644 --- a/includes/libs/HashRing.php +++ b/includes/libs/HashRing.php @@ -26,14 +26,14 @@ * @since 1.22 */ class HashRing { - /** @var Array (location => weight) */ + /** @var array (location => weight) */ protected $sourceMap = []; - /** @var Array (location => (start, end)) */ + /** @var array (location => (start, end)) */ protected $ring = []; /** @var HashRing|null */ protected $liveRing; - /** @var Array (location => UNIX timestamp) */ + /** @var array (location => UNIX timestamp) */ protected $ejectionExpiries = []; /** @var int UNIX timestamp */ protected $ejectionNextExpiry = INF; @@ -83,7 +83,7 @@ class HashRing { * @param string $item * @return string Location */ - public function getLocation( $item ) { + final public function getLocation( $item ) { $locations = $this->getLocations( $item, 1 ); return $locations[0]; @@ -116,11 +116,12 @@ class HashRing { // If more locations are requested, wrap-around and keep adding them reset( $this->ring ); while ( count( $locations ) < $limit ) { - list( $location, ) = each( $this->ring ); + $location = key( $this->ring ); if ( $location === $primaryLocation ) { break; // don't go in circles } $locations[] = $location; + next( $this->ring ); } return $locations; @@ -135,19 +136,6 @@ class HashRing { return $this->sourceMap; } - /** - * Get a new hash ring with a location removed from the ring - * - * @param string $location - * @return HashRing|bool Returns false if no non-zero weighted spots are left - */ - public function newWithoutLocation( $location ) { - $map = $this->sourceMap; - unset( $map[$location] ); - - return count( $map ) ? new self( $map ) : false; - } - /** * Remove a location from the "live" hash ring * @@ -173,7 +161,7 @@ class HashRing { * @return HashRing * @throws UnexpectedValueException */ - public function getLiveRing() { + protected function getLiveRing() { $now = time(); if ( $this->liveRing === null || $this->ejectionNextExpiry <= $now ) { $this->ejectionExpiries = array_filter(