X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2FHashRing.php;h=4ddb8131d5245f84d78406900045b41adea57b71;hb=f1b861dec81ac636f0183b085ad79993962ffa5e;hp=e7a10997cca8e5f89df8aacb03de3556cd176f82;hpb=f93976872d7cd0ce405fb7522aecbf46f7823621;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/HashRing.php b/includes/libs/HashRing.php index e7a10997cc..4ddb8131d5 100644 --- a/includes/libs/HashRing.php +++ b/includes/libs/HashRing.php @@ -28,14 +28,14 @@ */ class HashRing { /** @var Array (location => weight) */ - protected $sourceMap = array(); + protected $sourceMap = []; /** @var Array (location => (start, end)) */ - protected $ring = array(); + protected $ring = []; - /** @var Array (location => (start, end)) */ + /** @var HashRing|null */ protected $liveRing; /** @var Array (location => UNIX timestamp) */ - protected $ejectionExpiries = array(); + protected $ejectionExpiries = []; /** @var integer UNIX timestamp */ protected $ejectionNextExpiry = INF; @@ -53,7 +53,7 @@ class HashRing { } $this->sourceMap = $map; // Sort the locations based on the hash of their names - $hashes = array(); + $hashes = []; foreach ( $map as $location => $weight ) { $hashes[$location] = sha1( $location ); } @@ -62,7 +62,7 @@ class HashRing { } ); // Fit the map to weight-proportionate one with a space of size RING_SIZE $sum = array_sum( $map ); - $standardMap = array(); + $standardMap = []; foreach ( $map as $location => $weight ) { $standardMap[$location] = (int)floor( $weight / $sum * self::RING_SIZE ); } @@ -70,7 +70,7 @@ class HashRing { $index = 0; foreach ( $standardMap as $location => $weight ) { // Location covers half-closed interval [$index,$index + $weight) - $this->ring[$location] = array( $index, $index + $weight ); + $this->ring[$location] = [ $index, $index + $weight ]; $index += $weight; } // Make sure the last location covers what is left @@ -98,7 +98,7 @@ class HashRing { * @return array List of locations */ public function getLocations( $item, $limit ) { - $locations = array(); + $locations = []; $primaryLocation = null; $spot = hexdec( substr( sha1( $item ), 0, 7 ) ); // first 28 bits foreach ( $this->ring as $location => $range ) { @@ -190,7 +190,7 @@ class HashRing { $this->ejectionNextExpiry = min( $this->ejectionExpiries ); } else { // common case; avoid recalculating ring $this->liveRing = clone $this; - $this->liveRing->ejectionExpiries = array(); + $this->liveRing->ejectionExpiries = []; $this->liveRing->ejectionNextExpiry = INF; $this->liveRing->liveRing = null;