Save This Page
Home » commons-collections-3.2.1-src » org.apache.commons » collections » [javadoc | source]
org.apache.commons.collections
public final class: BinaryHeap [javadoc | source]
java.lang.Object
   java.util.AbstractCollection
      org.apache.commons.collections.BinaryHeap

All Implemented Interfaces:
    PriorityQueue, Buffer, Collection

Deprecated! Replaced - by PriorityBuffer in buffer subpackage. Due to be removed in v4.0.

Binary heap implementation of PriorityQueue.

The PriorityQueue interface has now been replaced for most uses by the Buffer interface. This class and the interface are retained for backwards compatibility. The intended replacement is PriorityBuffer .

The removal order of a binary heap is based on either the natural sort order of its elements or a specified Comparator . The #pop() method always returns the first element as determined by the sort order. (The isMinHeap flag in the constructors can be used to reverse the sort order, in which case #pop() 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 #insert(Object) and #pop() operations perform in logarithmic time. The #peek() operation performs in constant time. All other operations perform in linear time or worse.

Note that this implementation is not synchronized. Use SynchronizedPriorityQueue to provide synchronized access to a BinaryHeap:

PriorityQueue heap = new SynchronizedPriorityQueue(new BinaryHeap());
Field Summary
 int m_size    The number of elements currently in this heap. 
 Object[] m_elements    The elements in this heap. 
 boolean m_isMinHeap    If true, the first element as determined by the sort order will be returned. If false, the last element as determined by the sort order will be returned. 
 Comparator m_comparator    The comparator used to order the elements 
Constructor:
 public BinaryHeap() 
 public BinaryHeap(Comparator comparator) 
    Constructs a new BinaryHeap that will use the given comparator to order its elements.
    Parameters:
    comparator - the comparator used to order the elements, null means use natural order
 public BinaryHeap(int capacity) 
 public BinaryHeap(boolean isMinHeap) 
 public BinaryHeap(int capacity,
    Comparator comparator) 
    Constructs a new BinaryHeap.
    Parameters:
    capacity - the initial capacity for the heap
    comparator - the comparator used to order the elements, null means use natural order
    Throws:
    IllegalArgumentException - if capacity is <= 0
 public BinaryHeap(boolean isMinHeap,
    Comparator comparator) 
    Constructs a new BinaryHeap.
    Parameters:
    isMinHeap - true to use the order imposed by the given comparator; false to reverse that order
    comparator - the comparator used to order the elements, null means use natural order
 public BinaryHeap(int capacity,
    boolean isMinHeap) 
 public BinaryHeap(int capacity,
    boolean isMinHeap,
    Comparator comparator) 
    Constructs a new BinaryHeap.
    Parameters:
    capacity - the initial capacity for the heap
    isMinHeap - true to use the order imposed by the given comparator; false to reverse that order
    comparator - the comparator used to order the elements, null means use natural order
    Throws:
    IllegalArgumentException - if capacity is <= 0
Method from org.apache.commons.collections.BinaryHeap Summary:
add,   clear,   get,   grow,   insert,   isEmpty,   isFull,   iterator,   peek,   percolateDownMaxHeap,   percolateDownMinHeap,   percolateUpMaxHeap,   percolateUpMaxHeap,   percolateUpMinHeap,   percolateUpMinHeap,   pop,   remove,   size,   toString
Methods from java.util.AbstractCollection:
add,   addAll,   clear,   contains,   containsAll,   isEmpty,   iterator,   remove,   removeAll,   retainAll,   size,   toArray,   toArray,   toString
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.commons.collections.BinaryHeap Detail:
 public boolean add(Object object) 
      Deprecated!
 public  void clear() 
      Deprecated!
    Clears all elements from queue.
 public Object get() 
      Deprecated!
    Returns the priority element. Same as #peek() .
 protected  void grow() 
      Deprecated!
    Increases the size of the heap to support additional elements
 public  void insert(Object element) 
      Deprecated!
    Inserts an element into queue.
 public boolean isEmpty() 
      Deprecated!
    Tests if queue is empty.
 public boolean isFull() 
      Deprecated!
    Tests if queue is full.
 public Iterator iterator() 
      Deprecated!
    Returns an iterator over this heap's elements.
 public Object peek() throws NoSuchElementException 
      Deprecated!
    Returns the element on top of heap but don't remove it.
 protected  void percolateDownMaxHeap(int index) 
      Deprecated!
    Percolates element down heap from the position given by the index.

    Assumes it is a maximum heap.

 protected  void percolateDownMinHeap(int index) 
      Deprecated!
    Percolates element down heap from the position given by the index.

    Assumes it is a minimum heap.

 protected  void percolateUpMaxHeap(int index) 
      Deprecated!
    Percolates element up heap from from the position given by the index.

    Assume it is a maximum heap.

 protected  void percolateUpMaxHeap(Object element) 
      Deprecated!
    Percolates a new element up heap from the bottom.

    Assume it is a maximum heap.

 protected  void percolateUpMinHeap(int index) 
      Deprecated!
    Percolates element up heap from the position given by the index.

    Assumes it is a minimum heap.

 protected  void percolateUpMinHeap(Object element) 
      Deprecated!
    Percolates a new element up heap from the bottom.

    Assumes it is a minimum heap.

 public Object pop() throws NoSuchElementException 
      Deprecated!
    Returns the element on top of heap and remove it.
 public Object remove() 
      Deprecated!
    Removes the priority element. Same as #pop() .
 public int size() 
      Deprecated!
    Returns the number of elements in this heap.
 public String toString() 
      Deprecated!
    Returns a string representation of this heap. The returned string is similar to those produced by standard JDK collections.