Package 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).
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
changePriority(QueueElement e, double priority)
Change the priority of queue elemente
topriority
.boolean
contains(QueueElement e)
Does the queue contain an element?QueueElement
extractMin()
Remove the top element of the queue.void
insert(QueueElement e)
Insert elemente
into the queue.QueueElement
min()
Return the top element of the queue.int
size()
The current size of the queue.QueueElement[]
toArray()
Returns any array containing all of the elements in the queue.
-
-
-
Method Detail
-
size
public int size()
Description copied from interface:PriorityQueue
The current size of the queue.- Specified by:
size
in interfacePriorityQueue
- Returns:
- current size
-
min
public QueueElement min()
Description copied from interface:PriorityQueue
Return the top element of the queue.- Specified by:
min
in interfacePriorityQueue
- 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 interfacePriorityQueue
- Returns:
- the element removed
-
changePriority
public void changePriority(QueueElement e, double priority)
Description copied from interface:PriorityQueue
Change the priority of queue elemente
topriority
. The element's position in the queue is adjusted as needed.- Specified by:
changePriority
in interfacePriorityQueue
- Parameters:
e
- the element that has been changedpriority
- the new priority
-
insert
public void insert(QueueElement e)
Description copied from interface:PriorityQueue
Insert elemente
into the queue.- Specified by:
insert
in interfacePriorityQueue
- 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 interfacePriorityQueue
- Parameters:
e
- the element- Returns:
- whether the queue contains the element
-
toArray
public QueueElement[] toArray()
Description copied from interface:PriorityQueue
Returns any array containing all of the elements in the queue. They are not guaranteed to be in any particular order.- Specified by:
toArray
in interfacePriorityQueue
-
-