*/
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;
}
$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 );
}
} );
// 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 );
}
$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
* @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 ) {
$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;