Queue

来源:互联网 发布:cf手游刷等级软件 编辑:程序博客网 时间:2024/06/10 02:46
name offer peak poll size comments PriorityQueue o(log(n)) o(1) o(log(n)) o(1) priority heap backed by array, reference:http://blog.csdn.net/pecywang/article/details/24024835 http://www.jianshu.com/p/9a456d1b59b5 LinkedList o(1) o(1) o(1) o(1) LinkedList underlying ArrayDequeue o(1) o(1) o(1) o(1) array underlying ConcurrentLinkedQueue o(1) o(1) o(1) o(n) head and tail node. node has item and next fields they are all volatile variables. use CAS algorithm without blocking. offer node at the tail of queue. poll node from the head of queue. CAS operation to set next of tail to new node. If failed, continue searching tail node by following next of current node. Or jump to tail node if tail is changed. Otherwise jump to head after sentinel node is found. != is not atomic. update head and tail after two hops. ArrayBlockingQueue o(1) o(1) o(1) o(1) array underlying PriorirityBlockingQueue o(log(n)) o(1) o(log(n)) o(1) priority heap based on array SynchronousQueue o(1) o(1) o(1) o(1) DealyQueue o(log(n)) o(1) o(log(n)) o(1) priority heap based on array LinkedBlockingQueue o(1) o(1) o(1) o(1)
原创粉丝点击