[][src]Crate hash32

32-bit hashing machinery


Because 32-bit architectures are a thing (e.g. ARM Cortex-M) and you don't want your hashing function to pull in a bunch of slow 64-bit compiler intrinsics (software implementations of 64-bit operations).

Relationship to core::hash

This crate exposes the same interfaces you'll find in core::hash: Hash, Hasher, BuildHasher and BuildHasherDefault. The main difference is that hash32::Hasher::finish returns a u32 instead of u64, and the contract of hash32::Hasher forbids the implementer from performing 64-bit (or 128-bit) operations while computing the hash.


The easiest way to implement hash32::Hash for a struct is to use the #[derive(Hash32)].

extern crate hash32_derive;

struct Ipv4Addr([u8; 4]);


This crate provides implementations of the following 32-bit hashing algorithms:


In the future we'd like to deprecate this crate in favor of making core::hash::Hasher generic over the size of the computed hash. Below is shown the planned change (but it doesn't work due to limitations in the associated_type_defaults feature):

This example is not tested

trait Hasher {
    type Hash = u64; // default type for backwards compatibility

    fn finish(&self) -> Self::Hash; // changed
    fn write(&mut self, bytes: &[u8]);

With this change a single #[derive(Hash)] would enough to make a type hashable with 32-bit and 64-bit hashers.



See core::hash::BuildHasherDefault for details


32-bit Fowler-Noll-Vo hasher


32-bit MurmurHash3 hasher



See core::hash::BuildHasher for details


See core::hash::Hash for details


See core::hash::Hasher for details