-
Notifications
You must be signed in to change notification settings - Fork 3
/
chained.h
65 lines (55 loc) · 1.21 KB
/
chained.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
#ifdef DEFAULT
#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"
using namespace std;
#define FETCH_REQ 0
#define INSERT_REQ 1
#define DELETE_REQ 2
typedef struct HashmapReq {
ulong key;
ulong value;
uint8_t reqType;
} HashmapReq;
typedef struct KV {
ulong key;
ulong value;
struct KV* next;
} KV;
class ChainedHashmap {
private:
int hashpower;
long cardinality;
ulong hmsize;
KV **dict;
KV *entries;
ulong entriesOffset = 0;
ulong numReqs = 0;
ulong displacement;
struct timespec startTime, endTime;
public:
ChainedHashmap();
void initHashpower(int);
void bulkLoad(ulong*, ulong);
Metrics processRequests(HashmapReq*, ulong);
void rehash();
void free();
// helper functions
ulong _random();
ulong _murmurHash(ulong);
void _fetch(HashmapReq*);
void _insert(HashmapReq*);
void _delete(HashmapReq*);
void _setFinal(ulong, ulong);
ulong _getTimeDiff(struct timespec, struct timespec);
int _getHashpower();
};
typedef ChainedHashmap Hashmap;
#endif // DEFAULT