繁体   English   中英

为什么将ConcurrentNavigableMap实现为跳过列表?

[英]Why is ConcurrentNavigableMap implemented as a skip list?

最近我碰到ConcurrentSkipListMap ,这是一个skip list实现ConcurrentNavigableMap 现在,我想知道为什么将它实现为skip list

skip list是否skip list 并发可导航地图的“标准”实现? 是什么让skip list特别有用呢?

ConcurrentSkipListMap源代码已记录了原因。

采用此方法而不是通常基于数组的方法有两个原因

  1. 基于数组的实现似乎遇到更多的复杂性和开销
  2. 对于遍历索引列表,我们可以使用比基本列表便宜的算法

这是javadoc

 /*
 * This class implements a tree-like two-dimensionally linked skip
 * list in which the index levels are represented in separate
 * nodes from the base nodes holding data.  **There are two reasons
 * for taking this approach instead of the usual array-based**
 * structure: 1) Array based implementations seem to encounter
 * more complexity and overhead 2) We can use cheaper algorithms
 * for the heavily-traversed index lists than can be used for the
 * base lists.  Here's a picture of some of the basics for a
 * possible list with 2 levels of index:
 *
 * Head nodes          Index nodes
 * +-+    right        +-+                      +-+
 * |2|---------------->| |--------------------->| |->null
 * +-+                 +-+                      +-+
 *  | down              |                        |
 *  v                   v                        v
 * +-+            +-+  +-+       +-+            +-+       +-+
 * |1|----------->| |->| |------>| |----------->| |------>| |->null
 * +-+            +-+  +-+       +-+            +-+       +-+
 *  v              |    |         |              |         |
 * Nodes  next     v    v         v              v         v
 * +-+  +-+  +-+  +-+  +-+  +-+  +-+  +-+  +-+  +-+  +-+  +-+
 * | |->|A|->|B|->|C|->|D|->|E|->|F|->|G|->|H|->|I|->|J|->|K|->null
 * +-+  +-+  +-+  +-+  +-+  +-+  +-+  +-+  +-+  +-+  +-+  +-+

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM