Struct djb_hash::x33a_u32_php::X33aU32Php[][src]

pub struct X33aU32Php { /* fields omitted */ }

Implements 32 bit version of one of the original hash functions post by Daniel J. Bernstein but with final OR to set the high bit.

PHP uses a zero hash value to signal an empty hash that will need to be calculated. To insure no actual hash ends up being zero a final step of binary OR is used to always set the high bit.

Examples

use std::hash::Hasher;
use djb_hash::HasherU32;
use djb_hash::x33a_u32_php::*;
let input = "Ez";
let mut hasher = X33aU32Php::new();
hasher.write(&input.as_bytes());
assert_eq!(hasher.finish(), 2153345956u64);
assert_eq!(hasher.finish_u32(), 2153345956u32);

Methods

impl X33aU32Php
[src]

Creates a new hash using the original 5381 prime number salt value used by DJB.

Creates a new hash using user supplied salt value.

The supplied salt needs to be a prime number. It should have bits in more than just the lower 8 bits but setting any bits past half the size of the hash is of limited use as they are quickly lost during the multiplication stage for long values and tend to because static for very short values. Primes between 16 to 32 bits for 64 bit hashes seem to work best in most cases and between 16 to 24 bits for 32 bit hashes.

Trait Implementations

impl HasherU32 for X33aU32Php
[src]

Returns a 32 bit hash instead of the normal 64 bit one. Read more

impl Hasher for X33aU32Php
[src]

Returns the hash value for the values written so far. Read more

Writes byte slice to hash.

Does hash * 33 + byte but is implemented as hash << 5 (*32) + hash + byte as this is faster on most processors vs normal multiplication.

Writes a single u8 into this hasher.

Writes a single u16 into this hasher.

Writes a single u32 into this hasher.

Writes a single u64 into this hasher.

Writes a single u128 into this hasher.

Writes a single usize into this hasher.

Writes a single i8 into this hasher.

Writes a single i16 into this hasher.

Writes a single i32 into this hasher.

Writes a single i64 into this hasher.

Writes a single i128 into this hasher.

Writes a single isize into this hasher.

Auto Trait Implementations

impl Send for X33aU32Php

impl Sync for X33aU32Php