hrw_hash/lib.rs
1#![doc = include_str!("../README.md")]
2#![forbid(unsafe_code)]
3
4mod hasher;
5mod hrw;
6mod weighted_hrw;
7
8use std::hash::Hash;
9
10pub use {
11 hasher::{DefaultNodeHasher, NodeHasher},
12 hrw::HrwNodes,
13 weighted_hrw::WeightedHrwNodes,
14};
15
16/// Target node which will be used for the hashing.
17pub trait Node: Hash + PartialEq + Eq {}
18
19impl<T> Node for T where T: Hash + PartialEq + Eq {}
20
21/// Weighted node which will be used for the hashing.
22pub trait WeightedNode: Node {
23 /// Capacity of the node.
24 ///
25 /// The capacity
26 /// what portion of the keyspace the affects the score of the node, thus the
27 /// higher the capacity, the more likely the node will be chosen.
28 ///
29 /// Capacities of all nodes are summed up to determine the total capacity of
30 /// the keyspace. The relative capacity of the node is then ratio of the
31 /// node's capacity to the total capacity of the keyspace.
32 fn capacity(&self) -> usize;
33}