Module fasthash::spooky [] [src]

SpookyHash: a 128-bit noncryptographic hash function

by Bob Jenkins

http://www.burtleburtle.net/bob/hash/spooky.html

Up to 4 bytes/cycle for long messages. Reasonably fast for short messages. All 1 or 2 bit deltas achieve avalanche within 1% bias per output bit.

This was developed for and tested on 64-bit x86-compatible processors. It assumes the processor is little-endian. There is a macro controlling whether unaligned reads are allowed (by default they are). This should be an equally good hash on big-endian machines, but it will compute different results on them than on little-endian machines.

Google's CityHash has similar specs to SpookyHash, and CityHash is faster on some platforms. MD4 and MD5 also have similar specs, but they are orders of magnitude slower. CRCs are two or more times slower, but unlike SpookyHash, they have nice math for combining the CRCs of pieces to form the CRCs of wholes. There are also cryptographic hashes, but those are even slower than MD5.

Examples

use std::hash::{Hash, Hasher};

use fasthash::{spooky, SpookyHasher};

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

let h = spooky::hash128(b"hello world\xff");

assert_eq!(h.low64(), hash(&"hello world"));

Structs

SpookyHash128

SpookyHash 128-bit hash functions

SpookyHash32

SpookyHash 32-bit hash functions

SpookyHash64

SpookyHash 64-bit hash functions

SpookyHasher128

An implementation of std::hash::Hasher and fasthash::HasherExt.

Functions

hash128

SpookyHash 128-bit hash functions for a byte array. For convenience, a 128-bit seed is also hashed into the result.

hash128_with_seed

SpookyHash 128-bit hash functions for a byte array.

hash32

SpookyHash 32-bit hash functions for a byte array.

hash32_with_seed

SpookyHash 32-bit hash functions for a byte array. For convenience, a 32-bit seed is also hashed into the result.

hash64

SpookyHash 64-bit hash functions for a byte array. For convenience, a 64-bit seed is also hashed into the result.

hash64_with_seed

SpookyHash 64-bit hash functions for a byte array.