-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSkipList.h
69 lines (47 loc) · 1.06 KB
/
SkipList.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
#ifndef LSM_KV__SKIPLIST_H_
#define LSM_KV__SKIPLIST_H_
#include <assert.h>
#include <random>
#include <stack>
#include <string>
#include <utility>
using namespace std;
class SkipList {
private:
random_device rd;
mt19937 mt;
struct Node {
Node *right, *down;
uint64_t key;
string value;
inline Node(uint64_t _key, string _value, Node *_right, Node *_down);
inline Node();
};
Node *head;
unsigned long length;
unsigned long valueSize;
inline bool shouldGrowUp();
public:
SkipList();
~SkipList();
void put(uint64_t key, const string &value);
string get(uint64_t key) const;
bool remove(uint64_t key);
void reset();
unsigned long getLength() const;
unsigned long getValueSize() const;
uint64_t getMinKey() const;
uint64_t getMaxKey() const;
class ConstIterator {
public:
explicit ConstIterator(Node *_p);
const uint64_t &key();
const string &value();
bool hasNext() const;
void next();
private:
Node *p;
};
ConstIterator constBegin() const;
};
#endif // LSM_KV__SKIPLIST_H_