-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShockHash1.h
41 lines (38 loc) · 1.34 KB
/
ShockHash1.h
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
#pragma once
#include <cmath>
#include <TinyBinaryCuckooHashTable.h>
/**
* ShockHash base case
*/
template <size_t leafSize>
class BijectionsShockHash1 {
static_assert(leafSize <= 64);
public:
inline size_t calculateBijection(std::vector<uint64_t> &keys) {
shockhash::TinyBinaryCuckooHashTable tinyBinaryCuckooHashTable(leafSize);
for (size_t i = 0; i < leafSize; i++) {
tinyBinaryCuckooHashTable.prepare(shockhash::HashedKey(keys[i]));
}
constexpr uint64_t allSet = (leafSize == 64) ? (~0ul) : (1ul << leafSize) - 1;
uint64_t mask = 0;
size_t x = 0;
for (;;) {
for (;;) {
mask = 0;
for (size_t i = 0; i < leafSize; i++) {
auto hash = shockhash::TinyBinaryCuckooHashTable::getCandidateCells(shockhash::HashedKey(keys[i]), x, leafSize);
mask |= (1ul << hash.cell1);
mask |= (1ul << hash.cell2);
}
if (mask == allSet) break;
x++;
}
if (tinyBinaryCuckooHashTable.construct(x)) break;
x++;
}
return x;
}
static std::string name() {
return "ShockHash";
}
};