about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/server/hashtable.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/server/hashtable.h b/src/server/hashtable.h
index 0fd0d2b..9d31cfc 100644
--- a/src/server/hashtable.h
+++ b/src/server/hashtable.h
@@ -1,5 +1,6 @@
 #pragma once
 
+#include <algorithm>
 #include <list>
 #include <vector>
 
@@ -16,4 +17,24 @@ private:
     size_t size;
 
     std::vector<std::list<std::pair<K, V>>> table;
+
+    std::hash<K> hash_function;
+
+    auto bucket_find_key(std::list<std::pair<K, V>> list, K key)
+    {
+        return std::find_if(list.begin(), list.end(), [&key](const std::pair<K, V>& pair) {
+            return pair.first == key;
+        });
+    }
+
+    bool bucket_contains_key(std::list<std::pair<K, V>> list, K key)
+    {
+        return bucket_find_key(list, key) != list.end();
+    }
+
+    std::list<std::pair<K, V>> get_bucket(K key)
+    {
+        size_t index = hash_function(key) % size;
+        return table.at(index);
+    }
 };