Starts implementing get method for neighbour based hashmap

This commit is contained in:
julien lengrand-lambert
2013-12-05 07:21:52 +01:00
parent b7364b40da
commit 6c6be8663c
2 changed files with 22 additions and 6 deletions

View File

@@ -168,8 +168,11 @@ class HMTableCollision(HashMap):
elif len(items) == 1:
return items[0].v # Returns correct value
else:
# TODO: Change this. Only return the correct result
return items # we return all the results if there are several
if [key in item.k for item in items]:
return item.v # result found
else:
return None # result not found
# TODO: Test this
def size(self):
return self._size
@@ -235,7 +238,22 @@ class HMNeighbourCollision():
Finds the element in the hash table that may contain the id for
the string we are looking for
"""
#TODO
my_key = self._hash(key)
items = self.hmap[my_key]
if items is None:
return items # Nothing found
else:
# We think the key is here.
# Test all the possible indexes for the key
# Stop when we reach the limits of the hasmaps
# or we find a free index
idx = my_key
cur_ptr = 1
negative = True
while(idx > 0 and idx < self._hash_size):
pass
# TODO: IMplement
def size(self):
return self._size

View File

@@ -77,9 +77,7 @@ class test_hash_map_table_collision(unittest.TestCase):
self.assertEqual(hm.get(key2), value2)
self.assertEqual(hm.get("Five"), None)
# Two tests to be done :
# Exact same key already exists : We return an error
# Different keys, but collision anyway, we return the correct value
# TODO: Different keys, but collision anyway, we return the correct value
#self.assertEqual(hm.get(key), )
class test_hash_map_with_item(unittest.TestCase):