Class ConsistentHash<T>
Consistent Hashing node ring implementation.
A good explanation of Consistent Hashing: http://weblogs.java.net/blog/tomwhite/archive/2007/11/consistent_hash.html
Note that toString of the ring nodes are used for the node hash, i.e. make sure it is different for different nodes.
Inherited Members
Namespace: Akka.Routing
Assembly: Akka.dll
Syntax
public class ConsistentHash<T>
Type Parameters
Name | Description |
---|---|
T | The type of objects to store in the hash. |
Constructors
| Edit this page View SourceConsistentHash(SortedDictionary<int, T>, int)
Initializes a new instance of the ConsistentHash<T> class.
Declaration
public ConsistentHash(SortedDictionary<int, T> nodes, int virtualNodesFactor)
Parameters
Type | Name | Description |
---|---|---|
SortedDictionary<int, T> | nodes | TBD |
int | virtualNodesFactor | TBD |
Exceptions
Type | Condition |
---|---|
ArgumentException | This exception is thrown if the given |
Properties
| Edit this page View SourceIsEmpty
Check to determine if the node ring is empty (i.e. no nodes added or all removed)
Declaration
public bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
bool |
Methods
| Edit this page View SourceAdd(T)
Adds a node to the hash ring.
Note that ConsistentHash<T> is immutable and this operation returns a new instance.
Declaration
public ConsistentHash<T> Add(T node)
Parameters
Type | Name | Description |
---|---|---|
T | node | The node to add to the hash ring |
Returns
Type | Description |
---|---|
ConsistentHash<T> | A new instance of this hash ring with the given node added. |
NodeFor(byte[])
Retrieves the node associated with the data key.
Declaration
public T NodeFor(byte[] key)
Parameters
Type | Name | Description |
---|---|---|
byte[] | key | The data key used for lookup. |
Returns
Type | Description |
---|---|
T | The node associated with the data key |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | This exception is thrown if the node ring is empty. |
NodeFor(string)
Retrieves the node associated with the data key.
Declaration
public T NodeFor(string key)
Parameters
Type | Name | Description |
---|---|---|
string | key | The data key used for lookup. |
Returns
Type | Description |
---|---|
T | The node associated with the data key |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | This exception is thrown if the node ring is empty. |
Remove(T)
Removes a node from the hash ring.
Note that ConsistentHash<T> is immutable and this operation returns a new instance.
Declaration
public ConsistentHash<T> Remove(T node)
Parameters
Type | Name | Description |
---|---|---|
T | node | The node to remove from the hash ring |
Returns
Type | Description |
---|---|
ConsistentHash<T> | A new instance of this hash ring with the given node removed. |
Operators
| Edit this page View Sourceoperator +(ConsistentHash<T>, T)
Adds a node to the hash ring.
Note that ConsistentHash<T> is immutable and this operation returns a new instance.
Declaration
public static ConsistentHash<T> operator +(ConsistentHash<T> hash, T node)
Parameters
Type | Name | Description |
---|---|---|
ConsistentHash<T> | hash | The hash ring used to derive a new ring with the given node added. |
T | node | The node to add to the hash ring |
Returns
Type | Description |
---|---|
ConsistentHash<T> | A new instance of this hash ring with the given node added. |
operator -(ConsistentHash<T>, T)
Removes a node from the hash ring.
Note that ConsistentHash<T> is immutable and this operation returns a new instance.
Declaration
public static ConsistentHash<T> operator -(ConsistentHash<T> hash, T node)
Parameters
Type | Name | Description |
---|---|---|
ConsistentHash<T> | hash | The hash ring used to derive a new ring with the given node removed. |
T | node | The node to remove from the hash ring |
Returns
Type | Description |
---|---|
ConsistentHash<T> | A new instance of this hash ring with the given node removed. |