Public Member Functions | Protected Member Functions | Properties

GridGain.Client.Hasher.GridClientConsistentHash< TNode > Class Template Reference

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

template<TNode >
bool GridGain.Client.Hasher.GridClientConsistentHash< TNode >.AddNode ( TNode  node,
int  replicas 
)
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.

template<TNode >
void GridGain.Client.Hasher.GridClientConsistentHash< TNode >.AddNodes ( ICollection< TNode >  nodes,
int  replicas 
)
Parameters:
nodes Nodes to add.
replicas Number of replicas for every node.
template<TNode >
GridGain.Client.Hasher.GridClientConsistentHash< TNode >.GridClientConsistentHash ( Object  affSeed  ) 
Parameters:
affSeed Affinity seed (will be used as key prefix for hashing).
template<TNode >
GridGain.Client.Hasher.GridClientConsistentHash< TNode >.GridClientConsistentHash ( IComparer< TNode >  nodesComp,
Object  affSeed 
)
Parameters:
nodesComp Nodes comparator to resolve hash codes collisions.
affSeed Affinity seed (will be used as key prefix for hashing).
template<TNode >
TNode GridGain.Client.Hasher.GridClientConsistentHash< TNode >.Node ( Object  key,
ICollection< TNode >  inc,
ICollection< TNode >  exc 
)
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.
template<TNode >
TNode GridGain.Client.Hasher.GridClientConsistentHash< TNode >.Node ( Object  key,
ICollection< TNode >  inc 
)
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.
template<TNode >
TNode GridGain.Client.Hasher.GridClientConsistentHash< TNode >.Node ( Object  key,
Predicate< TNode >  filter 
)
Parameters:
key Key to get node for.
filter Optional predicate for node filtering.
Returns:
Node for key, or null if node was not found.
template<TNode >
TNode GridGain.Client.Hasher.GridClientConsistentHash< TNode >.Node ( Object  key  ) 
Parameters:
key Key.
Returns:
Node.
template<TNode >
bool GridGain.Client.Hasher.GridClientConsistentHash< TNode >.RemoveNode ( TNode  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.

template<TNode >
internal int GridGain.Client.Hasher.GridClientConsistentHash< TNode >.SpreadHash ( Object  val  )  [protected]
Parameters:
val Value to get hash code for.
Returns:
Hash code.

Property Documentation

template<TNode >
int GridGain.Client.Hasher.GridClientConsistentHash< TNode >.Count [get]
Returns:
Number of distinct nodes, excluding replicas, in consistent hash.
template<TNode >
bool GridGain.Client.Hasher.GridClientConsistentHash< TNode >.IsEmpty [get]
Returns:
True if consistent hash is empty, null otherwise.
template<TNode >
IList<TNode> GridGain.Client.Hasher.GridClientConsistentHash< TNode >.Nodes [get]
Returns:
Set of all distinct nodes in the consistent hash.
template<TNode >
TNode GridGain.Client.Hasher.GridClientConsistentHash< TNode >.Random [get]
Returns:
Random node from consistent hash or null if there are no nodes.
template<TNode >
int GridGain.Client.Hasher.GridClientConsistentHash< TNode >.Size [get]
Returns:
Size of all nodes (including replicas) in consistent hash.