A Queue that ensure uniqueness of the elements?

前端 未结 8 1308
甜味超标
甜味超标 2020-12-13 08:25

I\'m looking for a implementation of java.util.Queue or something in the Google collection who behave like a Queue, but also ensure that each element of the queue is unique.

8条回答
  •  甜味超标
    2020-12-13 08:46

    Checking uniqueness of course has a cost (either in space or time). Seems like it might be interesting to work from something like a PriorityQueue which will maintain a heap sorted by Comparator of the elements. You might be able to leverage that to more efficiently (O(log n)) check existence without maintaining a side map.

    If you do want to wrap a Queue with a uniqueness checker, I would strongly recommend using the Google Collections ForwardingQueue to build such a thing.

提交回复
热议问题