33#include " VComparator.h"
44#include " UniversalHash.h"
55#include " OpenedHashNode.h"
6+ #include " OpenedHash.h"
7+
68
79const int DELETED = -1 ;
810
@@ -15,14 +17,13 @@ class OpenHashMap
1517 size_t tableSize;
1618 OpenHashNode<K, V>** table;
1719 VComparator<K> comp;
18- KeyHash<K> hashFunc;
19-
20+ OpenKeyHash<K> hashFunc;
2021public:
21- OpenHashMap (size_t tableSize):
22- hashFunc (tableSize),
22+ OpenHashMap (size_t tableSize, std::string hashType):
23+ tableSize (tableSize),
24+ hashFunc (tableSize, hashType),
2325 comp ()
2426 {
25- this ->tableSize = tableSize;
2627 table = new OpenHashNode<K, V>*[tableSize]();
2728 }
2829
@@ -39,13 +40,15 @@ class OpenHashMap
3940 bool insert (const K& key, const V& value)
4041 {
4142 unsigned int attempt = 0 ;
42- unsigned long hashValue = hashFunc[key];
43+ KeyAttempt<K> pairKA = {key, attempt};
44+ unsigned long hashValue = hashFunc[pairKA];
4345 OpenHashNode<K, V>* entry = table[hashValue];
4446 // std::cout <<"\nkey: " << key << " hash: " << hashValue << std::endl;
4547 while (entry != NULL && entry->getKey () != DELETED) {
4648 attempt++;
4749 // std::cout << attempt << " ";
48- hashValue = (hashFunc[key] + attempt) % tableSize;
50+ pairKA.attempt = attempt;
51+ hashValue = hashFunc[pairKA];
4952 entry = table[hashValue];
5053 if (attempt >= tableSize-1 )
5154 {
@@ -76,7 +79,8 @@ class OpenHashMap
7679 bool search (const K& key, V& value)
7780 {
7881 unsigned int attempt = 0 ;
79- unsigned long hashValue = hashFunc[key];
82+ KeyAttempt<K> pairKA = {key, attempt};
83+ unsigned long hashValue = hashFunc[pairKA];
8084 OpenHashNode<K, V>* entry = table[hashValue];
8185 while (entry != NULL ) {
8286 // std::cout << "hashkey: "<< hashValue << " value: " << entry->getValue() <<std::endl;
@@ -85,7 +89,8 @@ class OpenHashMap
8589 return true ;
8690 }
8791 attempt++;
88- hashValue = (hashFunc[key] + attempt) % tableSize;
92+ pairKA.attempt = attempt;
93+ hashValue = hashFunc[pairKA];// (hashFunc[key, attempt] + attempt) % tableSize;
8994 entry = table[hashValue];
9095 if (attempt >= tableSize-1 )
9196 {
@@ -103,12 +108,14 @@ class OpenHashMap
103108 void remove (const K& key)
104109 {
105110 unsigned int attempt = 0 ;
106- unsigned long hashValue = hashFunc[key];
111+ KeyAttempt<K> pairKA = {key, attempt};
112+ unsigned long hashValue = hashFunc[pairKA];
107113 OpenHashNode<K, V>* entry = table[hashValue];
108114
109115 while (entry != NULL && !comp.compare (entry->getKey (), key)) {
110116 attempt++;
111- hashValue = (hashFunc[key] + attempt) % tableSize;
117+ pairKA.attempt = attempt;
118+ hashValue = hashFunc[pairKA];// (hashFunc[key] + attempt) % tableSize;
112119 entry = table[hashValue];
113120 if (attempt >= tableSize-1 )
114121 {
0 commit comments