1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! Maglev hashing - A consistent hashing algorithm from Google
//!
//! [Maglev: A Fast and Reliable Software Network Load Balancer](https://static.googleusercontent.com/media/research.google.com/zh-CN//pubs/archive/44824.pdf)
//!
//! # Example
//!
//! ```rust
//! use maglev::*;
//!
//! let m = Maglev::new(vec!["Monday",
//!                          "Tuesday",
//!                          "Wednesday",
//!                          "Thursday",
//!                          "Friday",
//!                          "Saturday",
//!                          "Sunday"]);
//!
//! assert_eq!(m["alice"], "Friday");
//! assert_eq!(m["bob"], "Wednesday");
//!
//! // When the node list changed, ensure to use same `capacity` to rebuild the lookup table.
//!
//! let m = Maglev::with_capacity(vec!["Monday",
//!                                 // "Tuesday",
//!                                    "Wednesday",
//!                                 // "Thursday",
//!                                    "Friday",
//!                                    "Saturday",
//!                                    "Sunday"],
//!                               m.capacity());
//!
//! assert_eq!(m["alice"], "Friday");
//! assert_eq!(m["bob"], "Wednesday");
//! ```
//!
//! Maglev use `std::collections::hash_map::DefaultHasher` by default,
//! we could use the given hash builder to hash keys.
//!
//! ```rust
//! extern crate fasthash;
//! extern crate maglev;
//!
//! use fasthash::spooky::Hash128;
//!
//! use maglev::*;
//!
//! fn main() {
//!     let m = Maglev::with_hasher(vec!["Monday",
//!                                      "Tuesday",
//!                                      "Wednesday",
//!                                      "Thursday",
//!                                      "Friday",
//!                                      "Saturday",
//!                                      "Sunday"],
//!                                 Hash128 {});
//!
//!     assert_eq!(m["alice"], "Monday");
//!     assert_eq!(m["bob"], "Wednesday");
//! }
//! ```
mod conshash;
mod maglev;

pub use crate::conshash::ConsistentHasher;
pub use crate::maglev::Maglev;