MediaWiki  1.23.0
HashRing Class Reference

Convenience class for weighted consistent hash rings. More...

Public Member Functions

 __construct (array $map)
 
 getLocation ( $item)
 Get the location of an item on the ring. More...
 
 getLocations ( $item, $limit)
 Get the location of an item on the ring, as well as the next clockwise locations. More...
 
 getLocationWeights ()
 Get the map of locations to weight (ignores 0-weight items) More...
 
 newWithoutLocation ( $location)
 Get a new hash ring with a location removed from the ring. More...
 

Public Attributes

const RING_SIZE = 268435456
 

Protected Attributes

Array $ring = array()
 (location => (start, end)) * More...
 
Array $sourceMap = array()
 (location => weight) * More...
 

Detailed Description

Convenience class for weighted consistent hash rings.

Since
1.22

Definition at line 29 of file HashRing.php.

Constructor & Destructor Documentation

◆ __construct()

HashRing::__construct ( array  $map)
Parameters
array$map(location => weight)

Definition at line 38 of file HashRing.php.

References $hashes, array(), as, key, and RING_SIZE.

Member Function Documentation

◆ getLocation()

HashRing::getLocation (   $item)

Get the location of an item on the ring.

Parameters
string$item
Returns
string Location

Definition at line 78 of file HashRing.php.

References getLocations().

Referenced by JobQueueFederated\tryJobInsertions().

◆ getLocations()

HashRing::getLocations (   $item,
  $limit 
)

Get the location of an item on the ring, as well as the next clockwise locations.

Parameters
string$item
integer$limitMaximum number of locations to return
Returns
array List of locations

Definition at line 91 of file HashRing.php.

References $limit, array(), as, and list.

Referenced by getLocation().

◆ getLocationWeights()

HashRing::getLocationWeights ( )

Get the map of locations to weight (ignores 0-weight items)

Returns
array

Definition at line 126 of file HashRing.php.

References $sourceMap.

Referenced by JobQueueFederated\tryJobInsertions().

◆ newWithoutLocation()

HashRing::newWithoutLocation (   $location)

Get a new hash ring with a location removed from the ring.

Parameters
string$location
Returns
HashRing|bool Returns false if no non-zero weighted spots are left

Definition at line 136 of file HashRing.php.

References $sourceMap.

Referenced by JobQueueFederated\tryJobInsertions().

Member Data Documentation

◆ $ring

Array HashRing::$ring = array()
protected

(location => (start, end)) *

Definition at line 31 of file HashRing.php.

◆ $sourceMap

Array HashRing::$sourceMap = array()
protected

(location => weight) *

Definition at line 30 of file HashRing.php.

Referenced by getLocationWeights(), and newWithoutLocation().

◆ RING_SIZE

const HashRing::RING_SIZE = 268435456

Definition at line 33 of file HashRing.php.

Referenced by __construct().


The documentation for this class was generated from the following file: