#hash #hashing

fasthash

A suite of non-cryptographic hash functions for Rust

14 releases

0.3.2 Aug 6, 2018
0.3.1 Jul 28, 2018
0.2.8 Jan 22, 2018
0.2.6 May 10, 2017
0.1.1 Dec 25, 2016

#121 in Cryptography

Download history 54/week @ 2018-10-14 16/week @ 2018-10-21 68/week @ 2018-10-28 112/week @ 2018-11-04 192/week @ 2018-11-11 38/week @ 2018-11-18 144/week @ 2018-11-25 69/week @ 2018-12-02 155/week @ 2018-12-09 146/week @ 2018-12-16 54/week @ 2018-12-23 63/week @ 2018-12-30 58/week @ 2019-01-06 60/week @ 2019-01-13 80/week @ 2019-01-20

150 downloads per month
Used in 2 crates

Apache-2.0

1MB
29K SLoC

C++ 17K SLoC // 0.1% comments C 8K SLoC // 0.2% comments Rust 4K SLoC // 0.2% 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, base on a forked smhasher.

Usage

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

[dependencies]
fasthash = "0.3"

Then, add this to your crate root

extern crate fasthash;

use fasthash::*;

And then, use hash function with module or hasher

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

Or work with 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");

It also works with HashMap or HashSet, act as the hash function

use std::collections::HashSet;

use fasthash::spooky::SpookyHash128;

let mut set = HashSet::with_hasher(SpookyHash128 {});
set.insert(2);

Or use RandomState with a random seed.

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");

Goal

  • High performance
  • Zero cost binding
  • Compatibility with libstd/libcollection

Features

Performance

To bench the hash function, we need nighly rust

$ cargo +nightly bench

Please check smhasher reports for more details.

Dependencies

~1MB

  • build build.rs
  • dev fnv 1.0
  • dev rand 0.5