Skip to content

Instantly share code, notes, and snippets.

@thushan
Created January 22, 2015 06:24
Show Gist options
  • Select an option

  • Save thushan/e0afaf3f535d425ee3ed to your computer and use it in GitHub Desktop.

Select an option

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

talesin commented Jan 22, 2015

Copy link
Copy Markdown

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

thushan commented Jan 23, 2015

Copy link
Copy Markdown
Author

Love your work!

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