Skip to content

Instantly share code, notes, and snippets.

@vishalkuo
Created August 14, 2016 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vishalkuo/e5a9960866f64902e160ad571e8ce773 to your computer and use it in GitHub Desktop.
Save vishalkuo/e5a9960866f64902e160ad571e8ce773 to your computer and use it in GitHub Desktop.
An implementation of the Jenkins Hash in Rust.
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