Skip to content

Instantly share code, notes, and snippets.

@timendum
Created July 27, 2011 10:04
Show Gist options
  • Save timendum/1109054 to your computer and use it in GitHub Desktop.
Save timendum/1109054 to your computer and use it in GitHub Desktop.
Javascript String hash
function stringHash(s) {
var hash = 0,
i = 0,
char;
if (s.length === 0) {
return hash;
}
for (i = 0; i < s.length; i++) {
char = s.charCodeAt(i);
hash = 31*hash+char;
hash = hash & hash;
}
return hash;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment