edu.umass.cs.mallet.base.util.search
Class MinHeap

java.lang.Object
  extended byedu.umass.cs.mallet.base.util.search.MinHeap
All Implemented Interfaces:
PriorityQueue

public class MinHeap
extends java.lang.Object
implements PriorityQueue

Created by IntelliJ IDEA. User: pereira Date: Jun 18, 2005 Time: 9:11:24 PM Binary heap implementation of PriorityQueue. Based on algorithm in Corman, Leiserson, Rivest, and Stein (Section 6.5).


Constructor Summary
MinHeap()
          Create a binary heap with minimum initial capacity.
MinHeap(int capacity)
          Create a binary heap with initial capacity capacity.
 
Method Summary
 boolean contains(QueueElement e)
          Does the queue contain an element?
 void decreaseKey(QueueElement e, double priority)
          Lower the priority of queue element e to priorrity.
 QueueElement extractMin()
          Remove the top element of the queue.
 void insert(QueueElement e)
          Insert element e into the queue.
 QueueElement min()
          Return the top element of the queue.
 int size()
          The current size of the queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MinHeap

public MinHeap(int capacity)
Create a binary heap with initial capacity capacity. The heap's capacity grows as needed to accomodate insertions.

Parameters:
capacity - initial capacity

MinHeap

public MinHeap()
Create a binary heap with minimum initial capacity.

Method Detail

size

public int size()
Description copied from interface: PriorityQueue
The current size of the queue.

Specified by:
size in interface PriorityQueue
Returns:
current size

min

public QueueElement min()
Description copied from interface: PriorityQueue
Return the top element of the queue.

Specified by:
min in interface PriorityQueue
Returns:
top element of the queue

extractMin

public QueueElement extractMin()
Description copied from interface: PriorityQueue
Remove the top element of the queue.

Specified by:
extractMin in interface PriorityQueue
Returns:
the element removed

decreaseKey

public void decreaseKey(QueueElement e,
                        double priority)
Description copied from interface: PriorityQueue
Lower the priority of queue element e to priorrity. The element's position in the queue is adjusted as needed. IllegalArgumentExceptions are thrown if the element is not in the queue or if the new priority value is greater than the old value.

Specified by:
decreaseKey in interface PriorityQueue
Parameters:
e - the element that has been changed
priority - the new priority

insert

public void insert(QueueElement e)
Description copied from interface: PriorityQueue
Insert element e into the queue.

Specified by:
insert in interface PriorityQueue
Parameters:
e - the element to insert

contains

public boolean contains(QueueElement e)
Description copied from interface: PriorityQueue
Does the queue contain an element?

Specified by:
contains in interface PriorityQueue
Parameters:
e - the element
Returns:
whether the queue contains the element