#hash #hashing

fasthash

A suite of non-cryptographic hash functions for Rust

15 unstable releases (3 breaking)

0.4.0 Mar 13, 2019
0.3.2 Aug 6, 2018
0.3.1 Jul 28, 2018
0.2.8 Jan 22, 2018
0.1.1 Dec 25, 2016

#65 in Cryptography

Download history 81/week @ 2019-01-21 71/week @ 2019-01-28 76/week @ 2019-02-04 31/week @ 2019-02-11 56/week @ 2019-02-18 149/week @ 2019-02-25 103/week @ 2019-03-04 130/week @ 2019-03-11 113/week @ 2019-03-18 160/week @ 2019-03-25 69/week @ 2019-04-01 66/week @ 2019-04-08 70/week @ 2019-04-15 75/week @ 2019-04-22 52/week @ 2019-04-29

426 downloads per month
Used in 7 crates

Apache-2.0

1MB
29K SLoC

C++ 17K SLoC // 0.1% comments C 8K SLoC // 0.2% comments Rust 4K SLoC // 0.3% comments Assembly 306 SLoC // 0.3% comments Shell 31 SLoC // 0.2% comments Batch 17 SLoC Perl 10 SLoC

rust-fasthash travis build crate docs

A suite of non-cryptographic hash functions for Rust, binding the smhasher.

Usage

[dependencies]
fasthash = "0.4"

hash and hash_with_seed function

use fasthash::*;

let h = city::hash64("hello world");

let h = metro::hash64_with_seed("hello world", 123);

std::hash::Hash

use std::hash::Hash;

use fasthash::MetroHasher;

fn hash<T: Hash>(t: &T) -> u64 {
    let mut s = MetroHasher::new();
    t.hash(&mut s);
    s.finish()
}

hash(&"hello world");

HashMap and HashSet

use std::collections::HashSet;

use fasthash::spooky::SpookyHash128;

let mut set = HashSet::with_hasher(SpookyHash128);

set.insert(2);

RandomState

use std::collections::HashMap;

use fasthash::RandomState;
use fasthash::city::CityHash64;

let s = RandomState::<CityHash64>::new();
let mut map = HashMap::with_hasher(s);

assert_eq!(map.insert(37, "a"), None);
assert_eq!(map.is_empty(), false);

map.insert(37, "b");
assert_eq!(map.insert(37, "c"), Some("b"));
assert_eq!(map[&37], "c");

Hash Functions

Benchmark

$ cargo bench

Dependencies

~1MB
~12K SLoC