Last active
April 20, 2019 19:21
-
-
Save edwintcloud/d80b9fc0eb4e1b9441dd8eb22eae027b to your computer and use it in GitHub Desktop.
djb2 string hashing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _hash_str(self, string): | |
"""hash_str uses the djb2 algorithm to compute the hash | |
value of a string http://www.cse.yorku.ca/~oz/hash.html""" | |
hash = 5381 | |
for char in string[1:]: | |
# (hash << 5) + hash is equivalent to hash * 33 | |
hash = (hash << 5) + hash + ord(char) | |
return hash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment