Skip to content

Commit 1676990

Browse files
committed
HashTable: Implemented the get method (was previously pass)
1 parent 3faa385 commit 1676990

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

map/hashtable.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,19 @@ def put(self, key, value):
3737
hash_ = self.rehash(hash_)
3838

3939
def get(self, key):
40-
pass
40+
initial_hash = hash_ = self.hash(key)
41+
while True:
42+
if self._keys[hash_] is self._empty:
43+
# That key was never assigned
44+
return None
45+
elif self._keys[hash_] == key and self._values[hash_]:
46+
# key found
47+
return self._values[hash_]
48+
elif initial_hash == hash_:
49+
# table is full and wrapped around
50+
return None
51+
52+
hash_ = self.rehash(hash_)
4153

4254
def hash(self, key):
4355
return key % self.size

0 commit comments

Comments
 (0)