Skip to content

oronsh/rust-hash-ring

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rust-hash-ring

Consistent Hashing library for Rust

Crates.io crates.io Crates.io Build Status Build Status Coverage Status

Documentation

Usage

extern crate hash_ring;

use hash_ring::HashRing;
use hash_ring::NodeInfo;

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(("hello").to_string()).unwrap());

    println!("{}", hash_ring.get_node(("dude").to_string()).unwrap());

    println!("{}", hash_ring.get_node(("martian").to_string()).unwrap());

    println!("{}", hash_ring.get_node(("tardis").to_string()).unwrap());

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

    println!("{}", hash_ring.get_node(("hello").to_string()).unwrap());

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

    println!("{}", hash_ring.get_node(("hello").to_string()).unwrap());
}

Contributing

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

License

MIT

About

A consistent hashing library in Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%