This file contains hidden or 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
class Node(object): | |
def __init__(self, data): | |
"""Initialize this node with specified data""" | |
self.data = data | |
self.next = None | |
class LinkedList(object): | |
def __init__(self, items=None): |
This file contains hidden or 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 |
NewerOlder