Skip to content

Instantly share code, notes, and snippets.

@liufsd
Forked from hanleybrand/java_String_hashcode.py
Last active August 29, 2015 14:08
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 liufsd/e8ca6830d5825304b4fd to your computer and use it in GitHub Desktop.
Save liufsd/e8ca6830d5825304b4fd to your computer and use it in GitHub Desktop.
def java_string_hashcode(s):
h = 0
for c in s:
h = (31 * h + ord(c)) & 0xFFFFFFFF
return ((h + 0x80000000) & 0xFFFFFFFF) - 0x80000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment