Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions hashtable/hashtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class HashTable:
"""

def __init__(self, capacity):
# Your code here
self.capacity = MIN_CAPACITY
self.array = [None] * capacity


def get_num_slots(self):
Expand All @@ -35,6 +36,7 @@ def get_num_slots(self):
Implement this.
"""
# Your code here
return self.capacity


def get_load_factor(self):
Expand Down Expand Up @@ -62,7 +64,10 @@ def djb2(self, key):

Implement this, and/or FNV-1.
"""
# Your code here
hash = 5381
for c in key:
hash = (hash * 33) + ord(c)
return hash


def hash_index(self, key):
Expand All @@ -82,6 +87,8 @@ def put(self, key, value):
Implement this.
"""
# Your code here
i = self.hash_index(key)
self.array[i] = value


def delete(self, key):
Expand All @@ -93,6 +100,8 @@ def delete(self, key):
Implement this.
"""
# Your code here
i = self.hash_index(key)
self.array[i] = None


def get(self, key):
Expand All @@ -104,6 +113,8 @@ def get(self, key):
Implement this.
"""
# Your code here
i = self.hash_index(key)
return self.array[i]


def resize(self, new_capacity):
Expand Down