PHP Class Phan\Library\Hasher\Consistent

See https://en.wikipedia.org/wiki/Consistent_hashing
Inheritance: implements Phan\Library\Hasher
Show file Open project: etsy/phan

Protected Properties

Property Type Description
$_groupCount integer
$_hashRingGroups - Groups corresponding to hash values in _hashRingIds
$_hashRingIds - Sorted list of hash values, for binary search.

Public Methods

Method Description
__construct ( integer $groupCount )
generate_key_hash ( string $material ) : integer Returns a 30-bit signed integer (i.e. in the range [0, self::MAX-1]) Designed to work on 32-bit php installations as well.
getGroup ( string $key ) : integer Do a binary search in the consistent hashing ring to find the group.
get_hashes_for_group ( integer $group ) : array
reset ( ) : void No-op reset

Method Details

__construct() public method

public __construct ( integer $groupCount )
$groupCount integer

generate_key_hash() public static method

Returns a 30-bit signed integer (i.e. in the range [0, self::MAX-1]) Designed to work on 32-bit php installations as well.
public static generate_key_hash ( string $material ) : integer
$material string
return integer

getGroup() public method

Do a binary search in the consistent hashing ring to find the group.
public getGroup ( string $key ) : integer
$key string
return integer - an integer between 0 and $this->_groupCount - 1, inclusive

get_hashes_for_group() public static method

public static get_hashes_for_group ( integer $group ) : array
$group integer
return array

reset() public method

No-op reset
public reset ( ) : void
return void

Property Details

$_groupCount protected property

protected int $_groupCount
return integer

$_hashRingGroups protected property

- Groups corresponding to hash values in _hashRingIds
protected $_hashRingGroups

$_hashRingIds protected property

- Sorted list of hash values, for binary search.
protected $_hashRingIds