Java中的快速队列 [英] A fast queue in Java
问题描述
我正在寻找Java中的快速队列
实现。我看到 LinkedList
实现了 Queue
接口,但它只能与一样快LinkedList
对吗?有没有办法让队列更快,特别是添加
(我只需要 poll
,添加
并检查空
)。
我可能还需要一个 PriorityQueue
但还没有。
I am looking for a fast queue
implementation in Java. I see that LinkedList
implements the Queue
interface, but it will only be as fast as a LinkedList
right? Is there a way to have a queue that will be faster especially for add
(I only need poll
, add
and check for empty
).
Down the line I may also need a PriorityQueue
but not yet.
推荐答案
我看到LinkedList实现了Queue接口,但它只能和LinkedList一样快吗?
I see that LinkedList implements the Queue interface, but it will only be as fast as a LinkedList right?
注意源代码,LinkedList对于Queue.add,Queue.poll和Queue.peek操作是O(1)。
Eyeballing the source code, LinkedList is O(1) for Queue.add, Queue.poll, and Queue.peek operations.
我希望是足够快。
这篇关于Java中的快速队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!