Skip to content

Commit

Permalink
Fixed some initial issues
Browse files Browse the repository at this point in the history
  • Loading branch information
famavott committed Dec 3, 2017
1 parent 913c744 commit 9500a56
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
class HashTable(object):
"""HashTable class."""

def __init__(self, size, hash_type='additive'):
def __init__(self, size=10, hash_type='additive'):
"""Create new HashTable object."""
self.size = size
self.hash_type = hash_type
self.buckets = []
if self.hash_type != 'additive' or self.hash_type != 'oat':
raise ValueError("Cannot execute given hash type")
if hash_type not in ('additive', 'oat'):
raise ValueError('Hash funciton unsupported')
for i in range(size):
self.buckets.append([])

def _hash(self, key):
"""Hash string from user on get method."""
Expand All @@ -34,13 +36,13 @@ def set(self, key, val):
"""Add a key/val pair to HashTable."""
idx = self._hash(key)
pair = [key, val]
if self.buckets[idx] is None:
self.buckets[idx] = pair
if not self.buckets[idx]:
self.buckets[idx].append(pair)
else:
for item in self.buckets[idx]:
if item[0] == key:
item[1] = val
self.buckets[idx].append[pair]
self.buckets[idx].append(list(pair))

def get(self, key):
"""Get value at given key."""
Expand Down

0 comments on commit 9500a56

Please sign in to comment.