hrw-hash
A minimalistic implementation of the Highest Random Weight (HRW) aka Rendezvous hashing algorithm as described in the "A name-based mapping scheme for Rendezvous", by Thaler and Ravishankar (1996).
The weighted variant of the HRW algorithm is implemented using Logarithmic Method as described in "Weighted distributed hash tables", by Schindelhauer and Schomaker (2005).
To constrain the number of hashing operations, the implementation hashes nodes and keys only once
(instead of nodes * keys hashes). This optimization idea is well presented in the
"Rendezvous Hashing: The Path to Faster Hashes Calculation"
blog.
Features
- Absolutely minimalistic implementation with sane defaults.
- Allow weighted nodes.
- Optimized for performance and memory usage. No wasted re-hashing.
Motivation
Given an iterator of nodes (IntoIterator<Item = Node>) the aim is to produce sorted list of
references to these nodes (Iterator<Item = &Node>) for any given key.
This list serves as priority-sorted list of destination nodes for the key.
Both weighted and non-weighted nodes are supported.
Usage
For non-weighted nodes:
use HrwNodes;
// Anything that implements `IntoIterator<Item = Hash + Eq>` can
// be used as list of target nodes.
let hrw = new;
// For a given key, get the iterator to node references
// (sorted by their weight).
let shard_id = 0;
let replicas: = hrw.sorted
.take.collect;
assert_eq!;
For weighted nodes, which can have different capacities:
use ;
// Define node
// (anything that implements `Hash + Eq` can be used as node).
// Implement `WeightedNode` trait for the node.
let mut nodes = Vecnew;
for i in 0..100
// Add some nodes with higher capacities.
nodes.push;
nodes.push;
let hrw = new;
// Nodes `100` and `101` have higher capacity, so they will be
// selected more often -- even though there are many other nodes.
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
License
MIT