#consistent-hashing #add

ringhash

Consistent hashing implementation

3 unstable releases

0.1.1 Jun 3, 2023
0.1.0 Jun 3, 2023
0.0.0 Jun 1, 2023

#1983 in Algorithms

27 downloads per month

MIT/Apache

14KB
298 lines

ringhash

Crates.io License Build Status

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–7.5MB
~48K SLoC