Crates.io | ringhash |
lib.rs | ringhash |
version | 0.1.1 |
source | src |
created_at | 2023-06-01 11:53:51.338448 |
updated_at | 2023-06-03 14:39:01.844046 |
description | Consistent hashing implementation |
homepage | |
repository | https://github.com/Millione/ringhash |
max_upload_size | |
id | 879669 |
size | 34,879 |
Consistent hashing implementation.
Add this to your Cargo.toml
:
[dependencies]
ringhash = "0.1"
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);
}
}
Dual-licensed under the MIT license and the Apache License (Version 2.0).
See LICENSE-MIT and LICENSE-APACHE for details.