#hash #hashing

sys fasthash-sys

A suite of non-cryptographic hash functions for Rust

12 releases

Uses old Rust 2015

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.0 Dec 25, 2016

#318 in FFI

Download history 1795/week @ 2023-08-10 2483/week @ 2023-08-17 2306/week @ 2023-08-24 2101/week @ 2023-08-31 2192/week @ 2023-09-07 2102/week @ 2023-09-14 1881/week @ 2023-09-21 1784/week @ 2023-09-28 1882/week @ 2023-10-05 2122/week @ 2023-10-12 1759/week @ 2023-10-19 1951/week @ 2023-10-26 2000/week @ 2023-11-02 1952/week @ 2023-11-09 2426/week @ 2023-11-16 1437/week @ 2023-11-23

8,136 downloads per month
Used in 25 crates (via fasthash)

Apache-2.0

1MB
28K SLoC

C++ 17K SLoC // 0.1% comments C 8K SLoC // 0.2% comments Rust 1.5K SLoC // 0.0% comments Visual Studio Project 1K SLoC Assembly 307 SLoC // 0.3% comments Visual Studio Solution 63 SLoC Shell 32 SLoC // 0.2% comments Batch 18 SLoC Perl 11 SLoC // 0.2% comments

Contains (ELF exe/lib, 2KB) src/smhasher/fhtw-elf64.o, (ELF exe/lib, 2KB) src/smhasher/falkhash-elf64.o, (Mach-o exe, 1KB) src/smhasher/falkhash-macho64.o, (Mach-o exe, 2KB) src/smhasher/fhtw-macho64.o

rust-fasthash Continuous integration 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, Hasher};

use fasthash::{MetroHasher, FastHasher};

fn hash<T: Hash>(t: &T) -> u64 {
    // Or use any of the `*Hasher` struct's available as aliases from
    // root or in their respective modules as Hasher32/64 and some 128.
    let mut s = MetroHasher::default();
    t.hash(&mut s);
    s.finish()
}

hash(&"hello world");

HashMap and HashSet

use std::collections::HashSet;

use fasthash::spooky::Hash128;

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

set.insert(2);

RandomState

use std::collections::HashMap;

use fasthash::RandomState;
use fasthash::city::Hash64;

let s = RandomState::<Hash64>::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

First install cargo-criterion:

$ cargo install cargo-criterion

Then you can use it to run Criterion-rs benchmarks:

$ cargo criterion

Dependencies