-
Notifications
You must be signed in to change notification settings - Fork 3
/
hot_wrapper.cpp
129 lines (117 loc) · 2.85 KB
/
hot_wrapper.cpp
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "hot_wrapper.h"
#include <algorithm>
#include <cassert>
#include <chrono>
#include <iostream>
#include <map>
#include <hot/singlethreaded/HOTSingleThreaded.hpp>
#include <idx/contenthelpers/IdentityKeyExtractor.hpp>
#include <idx/contenthelpers/OptionalValue.hpp>
typedef hot::singlethreaded::HOTSingleThreaded<uint64_t, idx::contenthelpers::IdentityKeyExtractor> HotSetUInt64;
namespace HotTrieUInt64
{
template<bool enforcedDep>
void HotTrieExecuteWorkload(WorkloadUInt64& workload)
{
printf("HotTrie executing workload, enforced dependency = %d\n", (enforcedDep ? 1 : 0));
HotSetUInt64 s;
printf("HotTrie populating initial values..\n");
{
AutoTimer timer;
rep(i, 0, workload.numInitialValues - 1)
{
s.insert(workload.initialValues[i]);
}
}
printf("HotTrie executing workload..\n");
{
AutoTimer timer;
if (enforcedDep)
{
uint64_t lastAnswer = 0;
rep(i, 0, workload.numOperations - 1)
{
uint32_t x = workload.operations[i].type;
x ^= (uint32_t)lastAnswer;
WorkloadOperationType type = (WorkloadOperationType)x;
uint64_t realKey = workload.operations[i].key ^ lastAnswer;
uint64_t answer;
switch (type)
{
case WorkloadOperationType::INSERT:
{
bool r = s.insert(realKey);
answer = r;
break;
}
case WorkloadOperationType::EXIST:
{
idx::contenthelpers::OptionalValue<uint64_t> result = s.lookup(realKey);
bool r = (result.mIsValid & (result.mValue == realKey));
answer = r;
break;
}
case WorkloadOperationType::LOWER_BOUND:
{
auto it = s.lower_bound(realKey);
if (it == s.end())
{
answer = 0xffffffffffffffffULL;
}
else
{
answer = *it;
}
break;
}
}
workload.results[i] = answer;
lastAnswer = answer;
}
}
else
{
rep(i, 0, workload.numOperations - 1)
{
uint64_t answer;
uint64_t realKey = workload.operations[i].key;
switch (workload.operations[i].type)
{
case WorkloadOperationType::INSERT:
{
bool r = s.insert(realKey);
answer = r;
break;
}
case WorkloadOperationType::EXIST:
{
idx::contenthelpers::OptionalValue<uint64_t> result = s.lookup(realKey);
bool r = (result.mIsValid & (result.mValue == realKey));
answer = r;
break;
}
case WorkloadOperationType::LOWER_BOUND:
{
auto it = s.lower_bound(realKey);
if (it == s.end())
{
answer = 0xffffffffffffffffULL;
}
else
{
answer = *it;
}
break;
}
}
workload.results[i] = answer;
}
}
}
printf("HotTrie workload completed.\n");
}
// explicitly instantiate template function
//
template void HotTrieExecuteWorkload<false>(WorkloadUInt64& workload);
template void HotTrieExecuteWorkload<true>(WorkloadUInt64& workload);
} // HotTrieUInt64