Generic consistent hash implementation controls key to node affinity using consistent hash algorithm. This class is thread-safe and does not have to be externally synchronized.
More...
Inherits GridGain::Client::Hasher::GridClientConsistentHash.
List of all members.
Public Member Functions |
| | GridClientConsistentHash () |
| | Constructs consistent hash using empty affinity seed.
|
| | GridClientConsistentHash (Object affSeed) |
| | Constructs consistent hash using given affinity seed.
|
| | GridClientConsistentHash (IComparer< TNode > nodesComp, Object affSeed) |
| | Constructs consistent hash using given affinity seed and hasher function.
|
| void | AddNodes (ICollection< TNode > nodes, int replicas) |
| | Adds nodes to consistent hash algorithm (if nodes are null or empty, then no-op).
|
| bool | AddNode (TNode node, int replicas) |
| | Adds a node to consistent hash algorithm.
|
| bool | RemoveNode (TNode node) |
| | Removes a node and all of its replicas.
|
| TNode | Node (Object key) |
| | Gets node for a key.
|
| TNode | Node (Object key, ICollection< TNode > inc) |
| | Gets node for a given key.
|
| TNode | Node (Object key, ICollection< TNode > inc, ICollection< TNode > exc) |
| | Gets node for a given key.
|
| TNode | Node (Object key, Predicate< TNode > filter) |
| | Gets node for a given key.
|
Protected Member Functions |
| internal int | SpreadHash (Object val) |
| | Gets hash code for a given object.
|
Properties |
| int | Count [get] |
| | Gets number of distinct nodes, excluding replicas, in consistent hash.
|
| int | Size [get] |
| | Gets size of all nodes (including replicas) in consistent hash.
|
| bool | IsEmpty [get] |
| | Checks if consistent hash has nodes added to it.
|
| TNode | Random [get] |
| | Picks a random node from consistent hash.
|
| IList< TNode > | Nodes [get] |
| | Gets set of all distinct nodes in the consistent hash (in no particular order).
|
Detailed Description
template<TNode>
class GridGain::Client::Hasher::GridClientConsistentHash-g< TNode >
For a good explanation of what consistent hashing is, you can refer to Tom White's Blog.
Member Function Documentation
- Parameters:
-
| node | New node (if null then no-op). |
| replicas | Number of replicas for the node. |
- Returns:
True if node was added, null if it is null or
is already contained in the hash.
- Parameters:
-
| nodes | Nodes to add. |
| replicas | Number of replicas for every node. |
- Parameters:
-
| affSeed | Affinity seed (will be used as key prefix for hashing). |
- Parameters:
-
| nodesComp | Nodes comparator to resolve hash codes collisions. |
| affSeed | Affinity seed (will be used as key prefix for hashing). |
- Parameters:
-
| key | Key to get node for. |
| inc | Optional inclusion set. Only nodes contained in this set may be returned. |
If null, then all nodes may be included.
- Parameters:
-
| exc | Optional exclusion set. Only nodes not contained in this set may be returned. |
If null, then all nodes may be returned.
- Returns:
- Node for key, or
null if node was not found.
- Parameters:
-
| key | Key to get node for. |
| inc | Optional inclusion set. Only nodes contained in this set may be returned. |
If null, then all nodes may be included.
- Returns:
- Node for key, or
null if node was not found.
- Parameters:
-
| key | Key to get node for. |
| filter | Optional predicate for node filtering. |
- Returns:
- Node for key, or
null if node was not found.
- Parameters:
-
- Returns:
- Node.
- Parameters:
-
| node | Node to remove (if null, then no-op). |
- Returns:
True if node was removed, True if node is True or
not present in hash.
- Parameters:
-
| val | Value to get hash code for. |
- Returns:
- Hash code.
Property Documentation
- Returns:
- Number of distinct nodes, excluding replicas, in consistent hash.
- Returns:
True if consistent hash is empty, null otherwise.
- Returns:
- Set of all distinct nodes in the consistent hash.
- Returns:
- Random node from consistent hash or
null if there are no nodes.
- Returns:
- Size of all nodes (including replicas) in consistent hash.