|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Heap
Collection with an extractMin
for efficiently getting
the minimum-cost element. Rather than just holding objects and
using a comparator to compare them (like java.util.TreeSet does),
implementations of this interface hold Heap.Entry objects, which
consist of an object and a real-valued cost. The
decreaseCost
method can be used to decrease an entry's
cost and update its position in the heap.
Nested Class Summary | |
---|---|
static interface |
Heap.Entry
Interface for entries in a heap. |
Method Summary | |
---|---|
Heap.Entry |
add(java.lang.Object o,
double cost)
Adds an entry to this heap for the given object and cost. |
void |
changeCost(Heap.Entry entry,
double newCost)
Changes the cost for the given entry. |
void |
decreaseCost(Heap.Entry entry,
double newCost)
Decreases the cost for the given entry. |
Heap.Entry |
extractMin()
Returns the minimum-cost entry in this heap and removes it from the heap. |
Heap.Entry |
peekMin()
Returns the minimum-cost entry in this heap, without modifying the heap. |
Methods inherited from interface java.util.Collection |
---|
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray |
Method Detail |
---|
Heap.Entry peekMin()
java.util.NoSuchElementException
- if the heap is emptyHeap.Entry extractMin()
java.util.NoSuchElementException
- if the heap is emptyHeap.Entry add(java.lang.Object o, double cost)
void decreaseCost(Heap.Entry entry, double newCost)
Warning: If the new cost is greater than the current one, this method will not produce an error message, but the heap may behave incorrectly.
void changeCost(Heap.Entry entry, double newCost)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |