LIPH's C++ Codes
skip_list.h
Go to the documentation of this file.
1#ifndef LIPH_CONTAINER_SKIP_LIST_H_
2#define LIPH_CONTAINER_SKIP_LIST_H_
3
4#include <functional>
5#include <limits>
6#include <list>
7
9
10namespace liph {
11
12template <class Key, class Compare = std::less<Key>, class Allocator = std::allocator<Key> >
14public:
15 class iterator;
16 skip_list(const Compare& cmp = Compare(), const Allocator& alloc = Allocator()) : cmp_(cmp), alloc_(alloc) {}
17 void insert(const Key& key);
18 bool contains(const Key& key) const;
19 bool empty() const { return size() == 0; }
20 int32_t size() const { return head_.size; }
21 int32_t max_size() const { return std::numeric_limits<int32_t>::max(); }
22 void clear();
23 iterator find(const Key& key);
24 const iterator find(const Key& key) const;
25 void erase(iterator pos);
26 void erase(const Key& key);
27
28public:
29 iterator begin();
30 const iterator begin() const;
31 iterator end();
32 const iterator end() const;
33
34private:
35 struct node_base {
36 std::list<node_base *> next;
37 };
38
39 struct node_header : public node_base {
40 int32_t size{0};
41 node_header() { this->next = {this}; }
42 node_base *base() { return this; }
43 };
44
45private:
46 const Compare cmp_;
47 const Allocator alloc_;
48 node_header head_;
49};
50
51template <class K, class C, class A>
52void skip_list<K, C, A>::insert(const K& key) {}
53
54template <class K, class C, class A>
55bool skip_list<K, C, A>::contains(const K& key) const {
56 return false;
57}
58
59} // namespace liph
60
61#endif // LIPH_CONTAINER_SKIP_LIST_H_
Definition: noncopyable.h:30
Definition: skip_list.h:13
iterator find(const Key &key)
void insert(const Key &key)
Definition: skip_list.h:52
void erase(const Key &key)
bool empty() const
Definition: skip_list.h:19
int32_t max_size() const
Definition: skip_list.h:21
void erase(iterator pos)
const iterator begin() const
const iterator end() const
iterator end()
skip_list(const Compare &cmp=Compare(), const Allocator &alloc=Allocator())
Definition: skip_list.h:16
int32_t size() const
Definition: skip_list.h:20
const iterator find(const Key &key) const
iterator begin()
bool contains(const Key &key) const
Definition: skip_list.h:55
Definition: algorithm.h:10