GitXplorerGitXplorer
f

rust-maglev

public
25 stars
1 forks
0 issues

Commits

List of commits on branch master.
Unverified
67d9f69f63711d082d2b80a9d0a0b9fe5e747e21

bump version

fflier committed 3 years ago
Verified
2f13f6df92f5af5c4506c4b3d60e18debb5052e9

Merge pull request #3 from Mnwa/remove-borrow-restrictions

fflier committed 3 years ago
Verified
eadb74a610b3edf8bdfe9b78860508e5442c18d0

Remove borrow restrictions

MMnwa committed 3 years ago
Unverified
3d1e1b179f4892bfcc41299d85cd3a3dfc4e6905

update document

fflier committed 4 years ago
Unverified
2910eb19345a3ac593406615bb136411b6e76f21

impl Index operator

fflier committed 4 years ago
Unverified
ad05d2581666c269123de251a5a40e587e01dfd5

get return Option<&N> for empty list, #1

fflier committed 4 years ago

README

The README file for this repository.

rust-maglev travis build crate docs

Google's consistent hashing algorithm

Usage

To use maglev, first add this to your Cargo.toml:

[dependencies]
maglev = "0.2"

And then, use Maglev with ConsistentHasher trait

use maglev::{ConsistentHasher, Maglev};

fn main() {
    let m = Maglev::new(vec!["Monday",
                            "Tuesday",
                            "Wednesday",
                            "Thursday",
                            "Friday",
                            "Saturday",
                            "Sunday"]);

    assert_eq!(m["alice"], "Friday");
    assert_eq!(m["bob"], "Wednesday");

    // When the node list changed, ensure to use same `capacity` to rebuild

    let m = Maglev::with_capacity(vec!["Monday",
                                  // "Tuesday",
                                    "Wednesday",
                                  // "Thursday",
                                    "Friday",
                                    "Saturday",
                                    "Sunday"],
                                m.capacity());

    assert_eq!(m["alice"], "Friday");
    assert_eq!(m["bob"], "Wednesday");
}

Maglev use std::collections::hash_map::DefaultHasher by default, we could use the given hash builder to hash keys.

use fasthash::spooky::Hash128;
use maglev::Maglev;

fn main() {
    let m = Maglev::with_hasher(vec!["Monday",
                                     "Tuesday",
                                     "Wednesday",
                                     "Thursday",
                                     "Friday",
                                     "Saturday",
                                     "Sunday"],
                                Hash128 {});

    assert_eq!(m["alice"], "Monday");
    assert_eq!(m["bob"], "Wednesday");
}