From 185fb6119a747bc3fe3eb648c2bd3a4bcf7b8aaa Mon Sep 17 00:00:00 2001 From: paintcrafter <166063718+paintcrafter@users.noreply.github.com> Date: Mon, 3 Jun 2024 18:12:49 +0200 Subject: [PATCH] Update HashTable2.hpp --- include/HashTable2.hpp | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/include/HashTable2.hpp b/include/HashTable2.hpp index 89c2e1e..1d33865 100644 --- a/include/HashTable2.hpp +++ b/include/HashTable2.hpp @@ -7,27 +7,26 @@ using namespace std; -template class CuckooHashTable { private: static const int MAX_LOOP = 50; struct Entry { - KeyType key; - ValueType value; + int key; + string value; bool occupied; Entry() : occupied(false) {} - Entry(KeyType k, ValueType v, bool occ) : key(k), value(v), occupied(occ) {} + Entry(int k, string v, bool occ) : key(k), value(v), occupied(occ) {} }; vector> tables; size_t table_size; - hash hash1; - hash hash2; + hash hash1; + hash hash2; void rehash() { - vector> old_elements; + vector> old_elements; for (const auto& table : tables) { for (const auto& entry : table) { if (entry.occupied) { @@ -42,17 +41,17 @@ class CuckooHashTable { } } - size_t hash_function1(const KeyType& key) const { + size_t hash_function1(const int& key) const { return hash1(key) % table_size; } - size_t hash_function2(const KeyType& key) const { + size_t hash_function2(const int& key) const { return hash2(key) % table_size; } - void swap(Entry& a, KeyType& key, ValueType& value) { - KeyType temp_key = a.key; - ValueType temp_value = a.value; + void swap(Entry& a, int& key, string& value) { + int temp_key = a.key; + string temp_value = a.value; a.key = key; a.value = value; @@ -69,9 +68,9 @@ class CuckooHashTable { ~CuckooHashTable() {} - void insert(const KeyType& key, const ValueType& value) { - KeyType current_key = key; - ValueType current_value = value; + void insert(const int& key, const string& value) { + int current_key = key; + string current_value = value; int count = 0; while (count < MAX_LOOP) { @@ -98,7 +97,7 @@ class CuckooHashTable { insert(current_key, current_value); } - void remove(const KeyType& key) { + void remove(const int& key) { size_t pos1 = hash_function1(key); if (tables[0][pos1].occupied && tables[0][pos1].key == key) { tables[0][pos1].occupied = false;