ringhash

Crates.ioringhash
lib.rsringhash
version0.1.1
sourcesrc
created_at2023-06-01 11:53:51.338448
updated_at2023-06-03 14:39:01.844046
descriptionConsistent hashing implementation
homepage
repositoryhttps://github.com/Millione/ringhash
max_upload_size
id879669
size34,879
LIU JIE (Millione)

documentation

https://docs.rs/ringhash/

README

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.

Commit count: 6

cargo fmt