当做笔记记录下来:)

相比于bTree,skiplist占用更多的空间。

而在并发的环境下skiplist会比bTree效率更高。

(bTree插入的时候需要rebalance,需要lock比较多的结点,而skiplist则只需要lock跟node相关的几个结点)

SkipList.h

 1 #define MAX_LEVEL 16
 2 
 3 typedef int KeyType;
 4 typedef int ValueType;
 5 
 6 typedef struct nodeStructure* Node;
 7 struct nodeStructure
 8 {
 9     KeyType key;
10     ValueType value;
11     Node forward[1];
12 };
13 
14 class SkipList
15 {
16 public:
17     SkipList();
18     Node createNode(int level, const KeyType& key, const ValueType& value);
19     void createList();
20     bool insert(const KeyType& key, const ValueType& value);
21     bool erase(const KeyType& key, ValueType& value);
22     bool search(const KeyType& key, ValueType& value);
23 private:
24     int randomLevel();
25 private:
26     int _level;
27     Node _header;
28 };
View Code

相关文章:

  • 2022-02-21
  • 2021-07-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2021-07-02
猜你喜欢
  • 2022-12-23
  • 2021-08-01
  • 2021-08-02
  • 2021-05-30
  • 2022-12-23
  • 2021-09-02
相关资源
相似解决方案