Skip to main content

djb2_hash

Function djb2_hash 

Source
pub fn djb2_hash(data: &[u8]) -> u64
Expand description

djb2 64-bit hash of a byte slice.

Classic algorithm attributed to Dan Bernstein. Uses the formula hash = hash * 33 + byte starting from the magic constant 5381.

Simple, fast, and produces reasonable distribution for ASCII text.

ยงExamples

use numrs2::new_modules::string_algorithms::djb2_hash;

let h = djb2_hash(b"hello");
assert_ne!(h, 0);