-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_hash_map.cpp
More file actions
42 lines (34 loc) · 1.17 KB
/
Copy pathtest_hash_map.cpp
File metadata and controls
42 lines (34 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <cassert>
#include "hash_map.hpp"
int main() {
std::cout << "Initializing Low-Latency Hash Map...\n";
LowLatencyHashMap kv_store(100);
// 1. Test Insert
kv_store.insert("AAPL", "150.25");
kv_store.insert("GOOGL", "2800.10");
kv_store.insert("MSFT", "300.50");
std::cout << "Current Size: " << kv_store.get_size() << "\n";
// 2. Test Get
std::string price;
if (kv_store.get("AAPL", price)) {
std::cout << "Found AAPL: " << price << "\n";
}
// 3. Test Update
kv_store.insert("AAPL", "155.00");
kv_store.get("AAPL", price);
std::cout << "Updated AAPL: " << price << "\n";
// 4. Test Delete
kv_store.remove("GOOGL");
if (!kv_store.get("GOOGL", price)) {
std::cout << "GOOGL successfully deleted.\n";
}
// 5. Test Linear Probing (Collision Handling)
// Even if keys collide, the linear probing will place them in the next available slot
// and correctly retrieve them.
kv_store.insert("TSLA", "700.00");
kv_store.get("TSLA", price);
std::cout << "Found TSLA: " << price << "\n";
std::cout << "All basic hash map tests passed!\n";
return 0;
}