并发容器ConcurrentSkipListMap,ConcurrentSkipListSet

老马说编程

ConcurrentSkipListSet也是基于ConcurrentSkipListMap实现的

特点

  • 所有操作都是无阻塞的,所有操作都可以并行,包括写

  • 实现了ConcurrentMap接口,直接支持一些原子复合操作(与ConcurrentHashMap类似)

  • 排序(与TreeMap一样),默认按键自然有序,可以传递比较器自定义排序,实现了SortedMap和NavigableMap接口。

public static void main(String[] args) {
    Map map = new ConcurrentSkipListMap<>(
            Collections.reverseOrder());
    map.put("a", "abstract");
    map.put("c", "call");
    map.put("b", "basic");
    System.out.println(map.toString());
}

输出有序的
{c=call, b=basic, a=abstract}

并发跳表SkipList

是基于链表的,在链表的基础上加了多层索引结构。


并发容器ConcurrentSkipListMap,ConcurrentSkipListSet_第1张图片

查找性能与二叉树类似,复杂度是O(log(N))
类似二分查找了,从最高层开始

并发容器ConcurrentSkipListMap,ConcurrentSkipListSet_第2张图片

不需要并发的跳表SkipList

更为高效的结构,数据和所有层的索引在一个节点中
对于一个元素,只有一个节点,只是每个节点的索引个数可能不同


并发容器ConcurrentSkipListMap,ConcurrentSkipListSet_第3张图片

你可能感兴趣的:(并发容器ConcurrentSkipListMap,ConcurrentSkipListSet)