Crate hash32[−][src]
32-bit hashing machinery
Why?
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.
#[derive(Hash32)]
The easiest way to implement hash32::Hash
for a struct
is to use the #[derive(Hash32)]
.
#[macro_use] extern crate hash32_derive; #[derive(Hash32)] struct Ipv4Addr([u8; 4]);
Hashers
This crate provides implementations of the following 32-bit hashing algorithms:
Future
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):
#![feature(associated_type_defaults)] 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.
Structs
BuildHasherDefault | See |
FnvHasher | 32-bit Fowler-Noll-Vo hasher |
Murmur3Hasher | 32-bit MurmurHash3 hasher |
Traits
BuildHasher | See |
Hash | See |
Hasher | See |