hash_ring 0.0.2

consistent hashing library for Rust
docs.rs failed to build hash_ring-0.0.2
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: hash_ring-0.2.0

rust-hash-ring

Consistent Hashing library for Rust

Build Status

Installation

Add hash_ring via your Cargo.toml

[dependencies]
hash_ring = "*"

Contributing

Just fork it, implement your changes and submit a pull request.

Usage

extern crate hash_ring;

use hash_ring::hash_ring::HashRing;

#[derive(Clone)]
struct NodeInfo {
    pub host: &'static str,
    pub port: u16
}

impl ToString for NodeInfo {
    fn to_string(&self) -> String {
        format!("{}:{}", self.host, self.port)
    }
}

fn main() {
    let mut nodes: Vec<NodeInfo> = Vec::new();
    nodes.push(NodeInfo{host: "localhost", port: 15324});
    nodes.push(NodeInfo{host: "localhost", port: 15325});
    nodes.push(NodeInfo{host: "localhost", port: 15326});
    nodes.push(NodeInfo{host: "localhost", port: 15327});
    nodes.push(NodeInfo{host: "localhost", port: 15328});
    nodes.push(NodeInfo{host: "localhost", port: 15329});

    let mut hash_ring: HashRing<NodeInfo> = HashRing::new(nodes, 10);

    println!("{}", hash_ring.get_node(String::from_str("hello")).to_string());

    println!("{}", hash_ring.get_node(String::from_str("dude")).to_string());

    println!("{}", hash_ring.get_node(String::from_str("martian")).to_string());

    println!("{}", hash_ring.get_node(String::from_str("tardis")).to_string());

    hash_ring.remove_node(&NodeInfo{host: "localhost", port: 15329});

    println!("{}", hash_ring.get_node(String::from_str("hello")).to_string());

    hash_ring.add_node(&NodeInfo{host: "localhost", port: 15329});

    println!("{}", hash_ring.get_node(String::from_str("hello")).to_string());
}

License

MIT