\Horde_Support_ConsistentHash

For a thorough description of consistent hashing, see http://www.spiteful.com/2008/03/17/programmers-toolbox-part-3-consistent-hashing/, and also the original paper: http://www8.org/w8-papers/2a-webserver/caching/paper2.html

Copyright 2007-2017 Horde LLC (http://www.horde.org/)

Summary

Methods
Properties
Constants
__construct()
get()
getNodes()
add()
addNodes()
remove()
hash()
No public properties found
No constants found
_updateCircle()
$_numberOfReplicas
$_circle
$_pointMap
$_pointCount
$_nodes
$_nodeCount
N/A
No private methods found
No private properties found
N/A

Properties

$_numberOfReplicas

$_numberOfReplicas : integer

Number of times to put each node into the hash circle per weight value.

Type

integer

$_circle

$_circle : array

Array representing our circle

Type

array

$_pointMap

$_pointMap : array

Numeric indices into the circle by hash position

Type

array

$_pointCount

$_pointCount : integer

Number of points on the circle

Type

integer

$_nodes

$_nodes : array

Array of nodes.

Type

array

$_nodeCount

$_nodeCount : integer

Number of nodes

Type

integer

Methods

__construct()

__construct(array  $nodes = array(), integer  $weight = 1, integer  $numberOfReplicas = 100) 

Create a new consistent hash, with initial $nodes at $numberOfReplicas

Parameters

array $nodes

Initial array of nodes to add at $weight.

integer $weight

The weight for the initial node list.

integer $numberOfReplicas

The number of points on the circle to generate for each node.

get()

get(string  $key) 

Get the primary node for $key.

Parameters

string $key

The key to look up.

getNodes()

getNodes(string  $key, integer  $count = 5) : array

Get an ordered list of nodes for $key.

Parameters

string $key

The key to look up.

integer $count

The number of nodes to look up.

Returns

array —

An ordered array of nodes.

add()

add(mixed  $node,   $weight = 1) 

Add $node with weight $weight

Parameters

mixed $node
$weight

addNodes()

addNodes(array  $nodes, integer  $weight = 1) 

Add multiple nodes to the hash with the same weight.

Parameters

array $nodes

An array of nodes.

integer $weight

The weight to add the nodes with.

remove()

remove(mixed  $node) 

Remove $node from the hash.

Parameters

mixed $node

hash()

hash(string  $key) : string

Expose the hash function for testing, probing, and extension.

Parameters

string $key

Returns

string —

Hash value

_updateCircle()

_updateCircle() 

Maintain the circle and arrays of points.