|
|||||||||
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(Comparator cmp)
The objects added will be ordered using the Comparator . |
|
ArrayHeap(Comparator 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. |
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. |
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(Comparator cmp)
Comparator
.
public ArrayHeap(Comparator 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 Collection<E>
add
in interface Set<E>
add
in class 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 Collection<E>
isEmpty
in interface Set<E>
isEmpty
in class AbstractCollection<E>
boolean
valuepublic int size()
size
in interface Heap<E>
size
in interface Collection<E>
size
in interface Set<E>
size
in class AbstractCollection<E>
int
valuepublic Iterator<E> iterator()
Heap
iterator
in interface Heap<E>
iterator
in interface Iterable<E>
iterator
in interface Collection<E>
iterator
in interface Set<E>
iterator
in class AbstractCollection<E>
Iterator
valuepublic void clear()
clear
in interface Collection<E>
clear
in interface Set<E>
clear
in class AbstractCollection<E>
public void dump()
public void verify()
public String toString()
toString
in class AbstractCollection<E>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |