|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractSet<E>
edu.stanford.nlp.util.ArrayHeap<E>
public class ArrayHeap<E>
Implements a heap as an ArrayList. Values are all implicit in the comparator passed in on construction. Decrease key is supported, though only lg(n). Unlike the previous implementation of this class, this heap interprets the addition of an existing element as a "change key" which gets ignored unless it actually turns out to be a decrease key. Note that in this implementation, changing the key of an object should trigger a change in the comparator's ordering for that object, but should NOT change the equality of that object.
| Constructor Summary | |
|---|---|
ArrayHeap(java.util.Comparator<? super E> cmp)
Create an ArrayHeap. |
|
ArrayHeap(java.util.Comparator<? super E> cmp,
int initCapacity)
|
|
| Method Summary | |
|---|---|
boolean |
add(E o)
Adds an object to the heap. |
void |
clear()
Clears the heap. |
int |
decreaseKey(E o)
Changes the position of an element o in the heap based on a change in the ordering of o. |
void |
dump()
|
E |
extractMin()
Finds the object with the minimum key, removes it from the heap, and returns it. |
boolean |
isEmpty()
Checks if the heap is empty. |
java.util.Iterator<E> |
iterator()
Returns an iterator over its elements, in order. |
E |
min()
Finds the object with the minimum key and returns it, without modifying the heap. |
int |
size()
Get the number of elements in the heap. |
java.lang.String |
toString()
Prints the array entries in sorted comparator order. |
void |
verify()
|
| Methods inherited from class java.util.AbstractSet |
|---|
equals, hashCode, removeAll |
| Methods inherited from class java.util.AbstractCollection |
|---|
addAll, contains, containsAll, remove, retainAll, toArray, toArray |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Set |
|---|
addAll, contains, containsAll, remove, retainAll, toArray, toArray |
| Constructor Detail |
|---|
public ArrayHeap(java.util.Comparator<? super E> cmp)
cmp - The objects added will be ordered using the Comparator.
public ArrayHeap(java.util.Comparator<? super E> cmp,
int initCapacity)
| Method Detail |
|---|
public E extractMin()
extractMin in interface Heap<E>public E min()
min in interface Heap<E>public boolean add(E o)
add in interface Heap<E>add in interface java.util.Collection<E>add in interface java.util.Set<E>add in class java.util.AbstractCollection<E>o - an Object value
public int decreaseKey(E o)
decreaseKey in interface Heap<E>o - an Object value
public boolean isEmpty()
isEmpty in interface Heap<E>isEmpty in interface java.util.Collection<E>isEmpty in interface java.util.Set<E>isEmpty in class java.util.AbstractCollection<E>boolean valuepublic int size()
size in interface Heap<E>size in interface java.util.Collection<E>size in interface java.util.Set<E>size in class java.util.AbstractCollection<E>int valuepublic java.util.Iterator<E> iterator()
Heap
iterator in interface Heap<E>iterator in interface java.lang.Iterable<E>iterator in interface java.util.Collection<E>iterator in interface java.util.Set<E>iterator in class java.util.AbstractCollection<E>Iterator valuepublic void clear()
clear in interface java.util.Collection<E>clear in interface java.util.Set<E>clear in class java.util.AbstractCollection<E>public void dump()
public void verify()
public java.lang.String toString()
toString in class java.util.AbstractCollection<E>
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||