-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntegerHashes.cpp
More file actions
36 lines (29 loc) · 835 Bytes
/
IntegerHashes.cpp
File metadata and controls
36 lines (29 loc) · 835 Bytes
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
#include "IntegerHashes.h"
#include <cmath>
IntegerHash::IntegerHash(uint64_t i, uint64_t m) {
this->i = i;
this->m = m;
}
DivisionHash::DivisionHash(uint64_t i, uint64_t m): IntegerHash(i, m) {
// Nothing else to do.
}
uint64_t DivisionHash::hash(uint64_t input) const {
return input * (i + 1) % m;
}
ReciprocalHash::ReciprocalHash(uint64_t i, uint64_t m): IntegerHash(i, m) {
this->b = double(1) / (i + 2);
}
uint64_t ReciprocalHash::hash(uint64_t input) const {
double temp = b * input;
temp -= std::floor(temp);
return temp * m;
}
SquareRootHash::SquareRootHash(uint64_t i, uint64_t m): IntegerHash(i, m) {
this->b = std::sqrt(4 * i + 3);
this->b -= std::floor(this->b);
}
uint64_t SquareRootHash::hash(uint64_t input) const {
double temp = b * input;
temp -= std::floor(temp);
return temp * m;
}