Binary heap implementation of
Buffer
that provides for removal based on
Comparator
ordering.
The removal order of a binary heap is based on either the natural sort order of its elements or a specified {@link Comparator}. The {@link #remove()} method always returns the first element as determinedby the sort order. (The ascendingOrder
flag in the constructors can be used to reverse the sort order, in which case {@link #remove()}will always remove the last element.) The removal order is not the same as the order of iteration; elements are returned by the iterator in no particular order.
The {@link #add(Object)} and {@link #remove()} operations performin logarithmic time. The {@link #get()} operation performs in constanttime. All other operations perform in linear time or worse.
Note that this implementation is not synchronized. Use {@link org.apache.commons.collections.BufferUtils#synchronizedBuffer(Buffer)} or{@link org.apache.commons.collections.buffer.SynchronizedBuffer#decorate(Buffer)}to provide synchronized access to a PriorityBuffer
:
Buffer heap = SynchronizedBuffer.decorate(new PriorityBuffer());
This class is Serializable from Commons Collections 3.2.
@since Commons Collections 3.0 (previously BinaryHeap v1.0)
@version $Revision: 646777 $ $Date: 2008-04-10 13:33:15 +0100 (Thu, 10 Apr 2008) $
@author Peter Donald
@author Ram Chidambaram
@author Michael A. Smith
@author Paul Jack
@author Stephen Colebourne
@author Steve Phelps