hrw_hash/
lib.rs

1#![doc = include_str!("../README.md")]
2#![forbid(unsafe_code)]
3
4mod hasher;
5mod hrw;
6
7use std::hash::Hash;
8
9pub use {hasher::DefaultHasher, hrw::HrwNodes};
10
11/// Target node which will be used for the hashing.
12pub trait HrwNode: Hash + PartialEq + Eq {
13    /// Capacity of the node.
14    ///
15    /// The capacity
16    /// what portion of the keyspace the affects the score of the node, thus the
17    /// higher the capacity, the more likely the node will be chosen.
18    ///
19    /// Capacities of all nodes are summed up to determine the total capacity of
20    /// the keyspace. The relative capacity of the node is then ratio of the
21    /// node's capacity to the total capacity of the keyspace.
22    fn capacity(&self) -> usize {
23        1
24    }
25}
26
27macro_rules! impl_hrwnode {
28    ($($t:ty),*) => {
29        $(impl HrwNode for $t {})*
30    };
31}
32
33impl_hrwnode!(
34    u8,
35    u16,
36    u32,
37    u64,
38    usize,
39    i8,
40    i16,
41    i32,
42    i64,
43    isize,
44    char,
45    String,
46    &str,
47    &[u8]
48);