I guess PriorityBlockingDeque wasn't high on the priority list..
A class I find missing in the new
java.util.concurrent package is PriorityBlockingDeque. Just like PriorityBlockingQueue, this class should be sorting its elements either by their natural order or by a supplied Comparator.
I fail to understand the reason for having this class obviously missing from the package, and because I need it very much, I decided to create a blocking wrapper around NavigableSet using locks and conditions. This uses NavigableSet's already existing methods of pollFirst, pollLast, first and last to fulfil the Deque interface.
Update: After some comments appeared I've realised that by using NavigableSet I do not allow for duplicate values on the Deque. Therefore, I've changed the implementation to use LinkedList internally, using Collections.sort calls to keep the list sorted. Unfortunately, this brings the basic add operation to O(n log(n)), instead of the O(log(n)) it used to be.
The code is fully available here, as part of the collections project, and some unit tests are available here.
I will later post how I used it, but let me know if you used it and if it was of any help (or filled with bugs..)
Comments (19)
Integer.MAX_VALUE, of course).pollFirstandpollLastfunctionality at all, as it doesn't implement theDequeinterface, unlikeLinkedList. However, a Deque implementation using a ring-array is definitely possible, and I'm sure there's a ring-array implementation somewhere out there to be used instead of re-writing it. However, as to what you said, take a look at theCollections.sortdocumentation: If I understand this correctly, this verifies what you said.