Trait Fnv

Source
pub trait Fnv
where Self: 'static + Copy + WrappingMul + BitXor<Output = Self>, u8: AsPrimitive<Self>,
{ const PRIME: Self; const OFFSET_BASIS: Self; // Provided methods fn fnv1<I>(self, data: I) -> Self where I: IntoIterator<Item = u8> { ... } fn fnv1a<I>(self, data: I) -> Self where I: IntoIterator<Item = u8> { ... } }
Expand description

Fowler-Noll-Vo Hashes

Both FNV-1 and FNV-1a are provided.

Note that:

  • FNV is not a cryptographic hash.
  • FNV is not resistant to “hash flooding” denial-of-service attacks.

Required Associated Constants§

Source

const PRIME: Self

The FNV prime

Source

const OFFSET_BASIS: Self

The FNV offset basis

Provided Methods§

Source

fn fnv1<I>(self, data: I) -> Self
where I: IntoIterator<Item = u8>,

Compute the Fowler-Noll-Vo hash FNV-1 (multiply before xor)

Source

fn fnv1a<I>(self, data: I) -> Self
where I: IntoIterator<Item = u8>,

Compute the Fowler-Noll-Vo hash FNV-1a (xor before multiply)

use yafnv::Fnv;

// Test vectors from
// https://datatracker.ietf.org/doc/draft-eastlake-fnv/21/
for (data, h32, h64) in [
    ("", 0x811c9dc5, 0xcbf29ce484222325),
    ("a", 0xe40c292c, 0xaf63dc4c8601ec8c),
    ("foobar", 0xbf9cf968, 0x85944171f73967e8),
] {
    let data = data.as_bytes().iter().copied();
    assert_eq!(u32::OFFSET_BASIS.fnv1a(data.clone()), h32);
    assert_eq!(u64::OFFSET_BASIS.fnv1a(data), h64);
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Fnv for u32

Source§

const PRIME: u32 = 16_777_619u32

Source§

const OFFSET_BASIS: u32 = 2_166_136_261u32

Source§

impl Fnv for u64

Source§

const PRIME: u64 = 1_099_511_628_211u64

Source§

const OFFSET_BASIS: u64 = 14_695_981_039_346_656_037u64

Source§

impl Fnv for u128

Source§

const PRIME: u128 = 309_485_009_821_345_068_724_781_371u128

Source§

const OFFSET_BASIS: u128 = 144_066_263_297_769_815_596_495_629_667_062_367_629u128

Implementors§