phylonet.heaps
Class MaxHeap<N extends java.lang.Number,D>

java.lang.Object
  extended by phylonet.heaps.MaxHeap<N,D>
Type Parameters:
N - is the type of number that is used as the key of the heap
D - is the type of object stored in the heap.
All Implemented Interfaces:
java.lang.Iterable<D>
Direct Known Subclasses:
BinaryMaxHeap

public abstract class MaxHeap<N extends java.lang.Number,D>
extends java.lang.Object
implements java.lang.Iterable<D>

Basic interface for a max heap. The class is iterable. It will retrieve the objects out of the heap in the order they would be removed via calls to removeMax.

Author:
Derek Ruths

Constructor Summary
MaxHeap()
           
 
Method Summary
abstract  D getMax()
           
static
<N1 extends java.lang.Number,D1>
MaxHeap<N1,D1>
getMaxHeap(int capacity)
           
abstract  N getMaxKey()
           
abstract  D getMin()
           
abstract  N getMinKey()
           
abstract  void insert(N key, D value)
          Insert a new (key,value) pair in to the heap.
abstract  boolean isEmpty()
           
 java.util.Iterator<D> iterator()
           
abstract  D removeMax()
          Remove the maximum (key,value) pair from the heap.
abstract  void updateMaxKey(N key)
          Change the key associated with the object that is currently at the top of the heap.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MaxHeap

public MaxHeap()
Method Detail

getMaxHeap

public static <N1 extends java.lang.Number,D1> MaxHeap<N1,D1> getMaxHeap(int capacity)
Returns:
an implementation of the MaxHeap interface.

getMinKey

public abstract N getMinKey()
Returns:
the minimum key in the heap.

getMin

public abstract D getMin()
Returns:
the object associated with the minimum key in the heap.

insert

public abstract void insert(N key,
                            D value)
Insert a new (key,value) pair in to the heap.


getMaxKey

public abstract N getMaxKey()
Returns:
the maximum key in the heap.

getMax

public abstract D getMax()
Returns:
the object associated with the maximum key in the heap.

removeMax

public abstract D removeMax()
Remove the maximum (key,value) pair from the heap.

Returns:
the value that was at the top of the heap.

isEmpty

public abstract boolean isEmpty()
Returns:
true if this heap contains no data.

updateMaxKey

public abstract void updateMaxKey(N key)
Change the key associated with the object that is currently at the top of the heap.


iterator

public java.util.Iterator<D> iterator()
Specified by:
iterator in interface java.lang.Iterable<D>
Returns:
an iterator over the values in the heap. The heap can be modified while an iterator is being used. Values are removed as calls are made to next.