Skip to content

Instantly share code, notes, and snippets.

@thushan
Created January 22, 2015 06:24
Show Gist options
  • Save thushan/e0afaf3f535d425ee3ed to your computer and use it in GitHub Desktop.
Save thushan/e0afaf3f535d425ee3ed to your computer and use it in GitHub Desktop.
int jhash(string value)
{
int h = 8388617;
char[] values = value.ToCharArray();
for(int i = 0; i< value.Length; i++)
h = ( (h << 1 | h >> 30) & 0x7fffffff ) ^ values[i];
return h;
}
@talesin
Copy link

talesin commented Jan 22, 2015

Nice, and easy to lend itself to a fold:

"Level 6 / 541 St Kilda Road, Melbourne 3004 VICTORIA, Australia"
.ToCharArray()
.Aggregate(8388617, (h, ch) => ((h << 1 | h >> 30) & 0x7fffffff) ^ ch)
"Level 6 / 541 St Kilda Road, Melbourne 3004 VICTORIA, Australia"
|> Seq.fold (fun h ch -> (((h <<< 1) ||| (h >>> 30)) &&& 0x7fffffff) ^^^ (int ch)) 8388617

@thushan
Copy link
Author

thushan commented Jan 23, 2015

Love your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment