Main Page   Packages   Class Hierarchy   Compound List   File List   Compound Members  

meapsoft.Heap Class Reference

Inheritance diagram for meapsoft.Heap:

Inheritance graph
[legend]
List of all members.

Detailed Description

Abstract implementation of the basic functions needed for a binary heap using java.util.Vector as a back end.

Unlike java.util.TreeSet, this data structure can handle duplicate entries. The implementations of the methods given here implement a MinHeap. It is abstract so that we can have a MinHeap class that supports deleteMin() and a MaxHeap class that supports deleteMax() but neither of them support both.

Author:
Ron Weiss (ronw@ee.columbia.edu)

Definition at line 45 of file Heap.java.

Public Methods

 Heap ()
 Creates an empty Heap.

 Heap (Comparator c)
 Use given Comparator for all comparisons between elements in this Heap.

 Heap (int capacity)
 Creates an empty Heap with the given capacity.

 Heap (Collection c)
 Create a new Heap containing the elements of the given Collection.

Object remove (int index)
 Remove the Object at the given index from the Heap.

boolean remove (Object o)
 Remove the Object o from the Heap and return true.

boolean add (Object o)
 Add o to the Heap.

boolean addAll (Collection c)
 Add the contents of a Collection to the Heap.

void rebuildHeap ()
 Ensure that every element in this heap obeys the heap property.

void sort ()
 Perform an in place heap sort on the data stored in this heap.

boolean isHeap ()
 Do the contents of this object currently obey the heap property?


Protected Methods

int cmp (int node1, int node2)
 Compare two Objects in this heap - wrapper around compareTo/Comparator.compare.


Constructor & Destructor Documentation

meapsoft.Heap.Heap Comparator    c [inline]
 

Use given Comparator for all comparisons between elements in this Heap.

Otherwise rely on compareTo methods and Comparable Objects.

Definition at line 70 of file Heap.java.


Member Function Documentation

void meapsoft.Heap.rebuildHeap   [inline]
 

Ensure that every element in this heap obeys the heap property.

Runs in linear time.

This is meant to be called if/when the Comparator associated with this object is modified.

Definition at line 187 of file Heap.java.

Referenced by meapsoft.Heap.add(), meapsoft.Heap.addAll(), and meapsoft.Heap.remove().

boolean meapsoft.Heap.remove Object    o [inline]
 

Remove the Object o from the Heap and return true.

Returns false if o is not in the Heap (as measured by o.equals()).

Definition at line 116 of file Heap.java.

References meapsoft.Heap.remove().

void meapsoft.Heap.sort   [inline]
 

Perform an in place heap sort on the data stored in this heap.

After calling sort, a call to this objects iterator() method will iterate through the data stored in the heap in ascending sorted order. This is not a stable sort.

Reimplemented in meapsoft.MinHeap.

Definition at line 202 of file Heap.java.


The documentation for this class was generated from the following file:
Generated on Tue Feb 6 19:02:29 2007 for MEAPsoft by doxygen1.2.18