eckit::RendezvousHash class

This class implements the Rendezvous or Highest Random Weight (HRW) hashing It is thread-safe, in terms that threads can add and remove nodes whilts others can compute the hash and obtain the rendezvous node

Public types

using Node = std::string
using Key = std::map<std::string, std::string>
using hash_func_ptr = std::string(*)(const std::string&)

Public static functions

static auto md5(const std::string& str) -> std::string

Constructors, destructors, conversion operators

RendezvousHash(const hash_func_ptr hash = &md5)
RendezvousHash(const std::vector<Node>& nodes, const hash_func_ptr hash = &md5)
~RendezvousHash()

Public functions

void hashOrder(const Key& key, std::vector<Node>& nodes)
Provide a list of nodes / indices in the list of nodes for the given key.
void hashOrder(const Key& key, std::vector<size_t>& indices)
auto addNode(const Node& node) -> bool
auto removeNode(const Node& node) -> bool

Function documentation

bool eckit::RendezvousHash::addNode(const Node& node)

Returns true is node insertion was successful

Adds node to node list. No effect if node already present

bool eckit::RendezvousHash::removeNode(const Node& node)

Returns true is node removal was successful

Removes node from node list. No effect if node not present