Created
August 14, 2016 03:43
-
-
Save vishalkuo/e5a9960866f64902e160ad571e8ce773 to your computer and use it in GitHub Desktop.
An implementation of the Jenkins Hash in Rust.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::num::Wrapping; | |
pub fn one_time_hash<T: ToString>(k: T) -> Wrapping<u32> { | |
let key = k.to_string(); | |
let mut hash= Wrapping(0u32); | |
for c in key.chars(){ | |
let tmp = Wrapping(c as u32); | |
hash += tmp; | |
hash += hash << 10; | |
hash ^= hash >> 6; | |
} | |
hash += hash << 3; | |
hash ^= hash >> 11; | |
hash += hash << 15; | |
hash | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment