-
Notifications
You must be signed in to change notification settings - Fork 83
/
tombstone_hashmap.h
101 lines (77 loc) · 1.94 KB
/
tombstone_hashmap.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
#ifndef HASHMAP_TOMBSTONE
#define HASHMAP_TOMBSTONE
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
#include <inttypes.h>
#include <string.h>
#include <stdio.h>
#include <string>
#include <iostream>
#include <limits>
#include "murmurhash3.h"
#include "hamming.h"
#include "hashmap.h"
#include "monitoring.h"
namespace hashmap
{
class TombstoneHashMap: public HashMap
{
public:
TombstoneHashMap(uint64_t size) {
buckets_ = NULL;
num_buckets_ = size;
probing_max_ = size;
DELETED_BUCKET = (Entry*)1;
}
virtual ~TombstoneHashMap() {
Close();
}
int Open();
int Close();
struct Entry
{
uint32_t size_key;
uint32_t size_value;
char *data;
};
struct Bucket
{
uint64_t hash;
struct Entry* entry;
};
int Get(const std::string& key, std::string* value);
int Put(const std::string& key, const std::string& value);
int Exists(const std::string& key);
int Remove(const std::string& key);
int Resize();
int Dump();
int CheckDensity();
int BucketCounts();
int GetBucketState(int index);
int FillInitIndex(uint64_t index_stored, uint64_t *index_init);
int FillDistanceToInitIndex(uint64_t index_stored, uint64_t *distance);
void GetMetadata(std::map< std::string, std::string >& metadata);
uint64_t GetMinInitDistance();
uint64_t GetMaxInitDistance();
private:
Bucket* buckets_;
uint64_t num_buckets_;
uint64_t num_buckets_used_;
uint64_t hash_function(const std::string& key) {
static char hash[16];
static uint64_t output;
MurmurHash3_x64_128(key.c_str(), key.size(), 0, hash);
memcpy(&output, hash, 8);
return output;
}
Entry* DELETED_BUCKET;
uint64_t probing_max_;
void UpdateInitDistance(uint64_t distance, int32_t increment);
void UpdateMinMaxInitDistance();
std::map<uint64_t, uint64_t> distances_;
uint64_t init_distance_min_;
uint64_t init_distance_max_;
};
}; // end namespace hashmap
#endif // HASHMAP_TOMBSTONE