3 unstable releases
0.1.1 | Jun 3, 2023 |
---|---|
0.1.0 | Jun 3, 2023 |
0.0.0 | Jun 1, 2023 |
#2074 in Algorithms
14KB
298 lines
ringhash
Consistent hashing implementation.
Usage
Add this to your Cargo.toml
:
[dependencies]
ringhash = "0.1"
Example
use ringhash::Consistent;
fn main() {
let c = Consistent::new();
c.add("cacheA");
c.add("cacheB");
c.add("cacheC");
let users = vec![
"user_mcnulty",
"user_bunk",
"user_omar",
"user_bunny",
"user_stringer",
];
println!("initial state [A, B, C]");
for u in users.iter() {
let server = c.get(u).unwrap();
println!("{} => {}", u, server);
}
c.add("cacheD");
c.add("cacheE");
println!("with cacheD, cacheE added [A, B, C, D, E]");
for u in users.iter() {
let server = c.get(u).unwrap();
println!("{} => {}", u, server);
}
c.remove("cacheC");
println!("with cacheC removed [A, B, D, E]");
for u in users.iter() {
let server = c.get(u).unwrap();
println!("{} => {}", u, server);
}
}
License
Dual-licensed under the MIT license and the Apache License (Version 2.0).
See LICENSE-MIT and LICENSE-APACHE for details.
Dependencies
~2.2–7.5MB
~50K SLoC