cc.mallet.util.search
Class MinHeap
- java.lang.Object
-
- cc.mallet.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 ofPriorityQueue. Based on algorithm in Corman, Leiserson, Rivest, and Stein (Section 6.5).
-
-
Constructor Summary
Constructors Constructor and Description MinHeap()Create a binary heap with minimum initial capacity.MinHeap(int capacity)Create a binary heap with initial capacitycapacity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidchangePriority(QueueElement e, double priority)Change the priority of queue elementetopriority.booleancontains(QueueElement e)Does the queue contain an element?QueueElementextractMin()Remove the top element of the queue.voidinsert(QueueElement e)Insert elementeinto the queue.QueueElementmin()Return the top element of the queue.intsize()The current size of the queue.QueueElement[]toArray()Returns any array containing all of the elements in the queue.
-
-
-
Constructor Detail
-
MinHeap
public MinHeap(int capacity)
Create a binary heap with initial capacitycapacity. 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:PriorityQueueThe current size of the queue.- Specified by:
sizein interfacePriorityQueue- Returns:
- current size
-
min
public QueueElement min()
Description copied from interface:PriorityQueueReturn the top element of the queue.- Specified by:
minin interfacePriorityQueue- Returns:
- top element of the queue
-
extractMin
public QueueElement extractMin()
Description copied from interface:PriorityQueueRemove the top element of the queue.- Specified by:
extractMinin interfacePriorityQueue- Returns:
- the element removed
-
changePriority
public void changePriority(QueueElement e, double priority)
Description copied from interface:PriorityQueueChange the priority of queue elementetopriority. The element's position in the queue is adjusted as needed.- Specified by:
changePriorityin interfacePriorityQueue- Parameters:
e- the element that has been changedpriority- the new priority
-
insert
public void insert(QueueElement e)
Description copied from interface:PriorityQueueInsert elementeinto the queue.- Specified by:
insertin interfacePriorityQueue- Parameters:
e- the element to insert
-
contains
public boolean contains(QueueElement e)
Description copied from interface:PriorityQueueDoes the queue contain an element?- Specified by:
containsin interfacePriorityQueue- Parameters:
e- the element- Returns:
- whether the queue contains the element
-
toArray
public QueueElement[] toArray()
Description copied from interface:PriorityQueueReturns any array containing all of the elements in the queue. They are not guaranteed to be in any particular order.- Specified by:
toArrayin interfacePriorityQueue
-
-
DataMelt 3.0 © DataMelt by jWork.ORG