|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--java.util.AbstractCollection
|
+--java.util.AbstractList
|
+--java.util.Vector
|
+--org.opencores.util.Heap
Priority queue using heap.
add and remove require maximum O(log(N)) time.
| Fields inherited from class java.util.Vector |
capacityIncrement,
elementCount,
elementData,
serialVersionUID |
| Fields inherited from class java.util.AbstractList |
modCount |
| Constructor Summary | |
Heap()
Constructs a heap with no elements. |
|
Heap(java.lang.Comparable[] array)
Constructs the heap in O(N) time, using a technique similar to bottom-up construction. |
|
| Method Summary | |
void |
add(java.lang.Comparable element)
Inserts key into the heap, and then upheaps that key to a position where the heap property is satisfied. |
private void |
exchange(int i,
int j)
Exchanges the elements stored at the two locations |
private static int |
left(int i)
Returns the Vector index of the left child. |
private static int |
parent(int i)
Returns the Vector index of the parent |
java.lang.Comparable |
remove()
Removes the minimum (top) element from the Heap, decreases the size of the heap by one, and returns the minimum element. |
boolean |
remove(java.lang.Comparable element)
Removes specified element from the Heap, decreases the size of the heap by one, and returns true |
void |
repair()
Reconstruct the heap in O(N) time. |
private static int |
right(int i)
Returns the Vector index of the right child. |
private void |
sift(int i)
Also known as downheap, restores the heap condition starting at node i and working its way down. |
| Methods inherited from class java.util.Vector |
add,
add,
addAll,
addAll,
addElement,
capacity,
clear,
clone,
contains,
containsAll,
copyInto,
elementAt,
elements,
ensureCapacity,
ensureCapacityHelper,
equals,
firstElement,
get,
hashCode,
indexOf,
indexOf,
insertElementAt,
isEmpty,
lastElement,
lastIndexOf,
lastIndexOf,
remove,
remove,
removeAll,
removeAllElements,
removeElement,
removeElementAt,
removeRange,
retainAll,
set,
setElementAt,
setSize,
size,
subList,
toArray,
toArray,
toString,
trimToSize |
| Methods inherited from class java.util.AbstractList |
iterator,
listIterator,
listIterator |
| Methods inherited from class java.lang.Object |
|
| Constructor Detail |
public Heap(java.lang.Comparable[] array)
array - constructs heap based on this arraypublic Heap()
| Method Detail |
public void repair()
private static final int left(int i)
i - indexprivate static final int right(int i)
i - indexprivate static final int parent(int i)
private final void exchange(int i,
int j)
i - index of first elementj - index of second elementprivate final void sift(int i)
i and working its way down.i - index of node to sift
public java.lang.Comparable remove()
throws java.util.NoSuchElementException
public void add(java.lang.Comparable element)
elt - object to insert
public boolean remove(java.lang.Comparable element)
throws java.util.NoSuchElementException
true if successful.
- Parameters:
element - element to delete- Returns:
- true if object found false otherwise
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||