Bounded PriorityBlockingQueue

后端 未结 9 1125
Happy的楠姐
Happy的楠姐 2021-01-01 17:47

PriorityBlockingQueue is unbounded, but I need to bound it somehow. What is the best way to achieve that?

For information, the bounded PriorityBlo

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-01 18:12

    There is another implementation here

    It seems to do what you are asking for:

    A BoundedPriorityQueue implements a priority queue with an upper bound on the number of elements. If the queue is not full, added elements are always added. If the queue is full and the added element is greater than the smallest element in the queue, the smallest element is removed and the new element is added. If the queue is full and the added element is not greater than the smallest element in the queue, the new element is not added.

提交回复
热议问题