-
Notifications
You must be signed in to change notification settings - Fork 0
/
skiplist.h
72 lines (55 loc) · 1.5 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
70
71
72
//
// Created by yichen_X on 2023/4/1.
//
#ifndef LSM_KV_SKIPLIST_H
#define LSM_KV_SKIPLIST_H
#include <vector>
#include <iostream>
#include <random>
#include <cmath>
#include <fstream>
#include "sstable.h"
#include "utils.h"
using namespace std;
class skiplist {
private:
int max_level;
int cur_level;
uint64_t memory_size;
uint64_t length;
int random_level();
mt19937 gen{random_device{}()};
uniform_real_distribution<double> dis;
public:
template<typename K, typename V>
struct node{
private:
uint64_t key{};
string value;
public:
node<K , V> **next;
int level{};
node()= default;
node(const K k, const V v, const int l): key(k), value(v), level(l){
next = new node<K,V>*[level + 1];
memset(next, 0, sizeof(node<K, V>*)*(level + 1));
}
~node() {
delete []next;
}
K get_key() const { return key;}
V get_value() const { return value;}
void set_value(const V& s) {value = s;}
};
node<uint64_t, string>* head;
explicit skiplist(int maxlevel = 16);
void put(uint64_t key, const string &s);
string get(uint64_t key) const;
uint64_t get_size() const;
uint64_t get_length() const;
uint64_t get_min_key() const;
uint64_t get_max_key() const;
void store_bloomfilter(sstable_cache*& ssc) const;
~skiplist();
};
#endif //LSM_KV_SKIPLIST_H