Merge "Http::getProxy() method to get proxy configuration"
[lhc/web/wiklou.git] / includes / libs / HashRing.php
index e7a1099..70ce31d 100644 (file)
  */
 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)) */
        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;