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
| Improve this Doc View SourceConsistentHash(SortedDictionary<Int32, T>, Int32)
Initializes a new instance of the ConsistentHash<T> class.
Declaration
public ConsistentHash(SortedDictionary<int, T> nodes, int virtualNodesFactor)
Parameters
Type | Name | Description |
---|---|---|
SortedDictionary<Int32, T> | nodes | TBD |
Int32 | virtualNodesFactor | TBD |
Exceptions
Type | Condition |
---|---|
ArgumentException | This exception is thrown if the given |
Properties
| Improve this Doc 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 |
---|---|
Boolean |
Methods
| Improve this Doc 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
| Improve this Doc View SourceAddition(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. |
Subtraction(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. |