-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.cpp
More file actions
55 lines (44 loc) · 1.53 KB
/
demo.cpp
File metadata and controls
55 lines (44 loc) · 1.53 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
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "hashmap.hpp"
#include <iostream>
int main()
{
// Create a HashMap with string keys and int values
optimap::HashMap<std::string, int> map;
std::cout << "Demonstrating OptiMap HashMap" << std::endl;
std::cout << "==============================" << std::endl;
// Insert some elements
std::cout << "\nInserting elements..." << std::endl;
map.insert("one", 1);
map.insert("two", 2);
map.insert("three", 3);
std::cout << "Map size: " << map.size() << std::endl;
// Find and print elements
std::cout << "\nFinding elements..." << std::endl;
auto val1 = map.find("two");
if (val1 != map.end())
{
std::cout << "Found key 'two' with value: " << val1->second << std::endl;
}
auto val2 = map.find("four");
if (val2 == map.end())
{
std::cout << "Key 'four' not found, as expected." << std::endl;
}
// Use iterators to print all elements
std::cout << "\nIterating over all elements:" << std::endl;
for (const auto& pair : map)
{
std::cout << "- {" << pair.first << ": " << pair.second << "}" << std::endl;
}
// Demonstrate erase
std::cout << "\nErasing 'one'..." << std::endl;
map.erase("one");
std::cout << "Map size after erase: " << map.size() << std::endl;
std::cout << "\nFinal map contents:" << std::endl;
for (const auto& pair : map)
{
std::cout << "- {" << pair.first << ": " << pair.second << "}" << std::endl;
}
std::cout << "\nDemonstration complete." << std::endl;
return 0;
}