forked from dendibakh/perf-ninja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.hpp
30 lines (25 loc) · 861 Bytes
/
solution.hpp
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
#include <vector>
#include <limits>
static constexpr std::size_t HASH_MAP_SIZE = 32 * 1024 * 1024 - 5;
static constexpr std::size_t NUMBER_OF_LOOKUPS = 1024 * 1024;
class hash_map_t {
static constexpr int UNUSED = std::numeric_limits<int>::max();
std::vector<int> m_vector;
std::size_t N_Buckets;
public:
hash_map_t(std::size_t size) : m_vector(size, UNUSED), N_Buckets(size) {}
bool insert(int val) {
int bucket = val % N_Buckets;
if (m_vector[bucket] == UNUSED) {
m_vector[bucket] = val;
return true;
}
return false;
}
bool find(int val) const {
int bucket = val % N_Buckets;
return m_vector[bucket] != UNUSED;
}
};
void init(hash_map_t* hash_map, std::vector<int>& lookups);
int solution(const hash_map_t* hash_map, const std::vector<int>& lookups);