Skip to content

Instantly share code, notes, and snippets.

View edwintcloud's full-sized avatar
🎯
Focusing

Edwin Cloud edwintcloud

🎯
Focusing
View GitHub Profile
@edwintcloud
edwintcloud / linked_list.py
Last active April 23, 2019 17:56
Linked List Implementation in Python
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):
@edwintcloud
edwintcloud / string_hash.py
Last active April 20, 2019 19:21
djb2 string hashing
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