-
Notifications
You must be signed in to change notification settings - Fork 3
/
chained_adaptive.h
107 lines (90 loc) · 2.12 KB
/
chained_adaptive.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
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
#ifdef VIP
#include <cstdio>
#include <cstdlib>
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <cmath>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include "metrics.h"
#define _INTEL_INTRINSICS_ 1
#if _INTEL_INTRINSICS_
#include "x86intrin.h"
#endif
using namespace std;
#define FETCH_REQ 0
#define INSERT_REQ 1
#define DELETE_REQ 2
#define ADAPTIVE 0
#define BENCHMARKING 1
#define DEFAULT 2
#define SENSING 3
typedef struct HashmapReq {
ulong key;
ulong value;
uint8_t reqType;
} HashmapReq;
typedef struct KV {
ulong key;
ulong value;
struct KV* next;
} KV;
typedef struct Acc
{
uint8_t accesses = 0;
struct Acc* next;
} Acc;
class ChainedAdaptive {
private:
int hashpower;
long cardinality;
ulong hmsize;
KV **dict;
KV *entries;
Acc **accessesDict;
Acc *accesses;
ulong entriesOffset = 0;
ulong accessesOffset = 0;
ulong numReqs = 0;
ulong numReqsSlab = 0;
struct timespec startTime, endTime;
int mode = -1;
// Algorithm configuration
int periodicity = 60;
float epoch_size_factor = 1.5;
double confidence_prct = 0.95;
int sample_size = 1000;
ulong displacement = 0;
ulong displacement_sq = 0;
ulong statReqCount = 0;
ulong displacementMetric = 0;
// Algorithm parameters
ulong epochSize = 0;
double u0, v0, w0; // estimated when benchmarking
double u1, v1, w1; // estimated when sensing
public:
ChainedAdaptive();
void initHashpower(int);
void bulkLoad(ulong*, ulong);
Metrics processRequests(HashmapReq*, ulong);
void rehash();
void free();
// helper functions
ulong _random();
ulong _murmurHash(ulong);
void _fetchDefault(HashmapReq*);
void _fetchAdaptive(HashmapReq*);
void _fetchBenchmark(HashmapReq*);
void _insert(HashmapReq*);
void _delete(HashmapReq*);
void _setFinal(ulong, ulong);
void _setFinalEnd(ulong, ulong);
ulong _getTimeDiff(struct timespec, struct timespec);
int _getHashpower();
void _resetAccesses();
void _clearCache();
};
typedef ChainedAdaptive Hashmap;
#endif // VIP