|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.limegroup.gnutella.util.BinaryHeap
A class for maintaining the objects in a binary heap form, i.e., a classic fixed-size priority queue. Its a MAX heap, i.e., the root of the heap is the element with max value. The objects to be inserted into the heap must implement java.lang.Comparable interface, as that is what is used for comparison purposes so as to order the objects in the heap form. While in the heap, these objects must not be mutated in a way that affects compareTo. This class is not synchronized; that is up to the user.
BinaryHeap now contains a constructor to allow dynamic resizing as well.
FixedsizePriorityQueueTest
Constructor Summary | |
BinaryHeap(java.lang.Comparable[] array)
Initializes the array with the passed array Also takes the length of the array and sets it as the currentSize as well as maxSize for the heap, and makes heap out of that. |
|
BinaryHeap(int maxSize)
Constructs a new fixed-size BinaryHeap. |
|
BinaryHeap(int maxSize,
boolean resizable)
Constructs a new BinaryHeap to initially hold the given number of elements. |
Method Summary | |
int |
capacity()
Returns the maximum number of elements in this without growing the heap. |
void |
clear()
|
java.lang.Comparable |
extractMax()
|
java.lang.Comparable |
getMax()
Returns the largest element in this, without modifying this. |
java.lang.Comparable |
insert(java.lang.Comparable x)
|
boolean |
isEmpty()
Returns true if this is empty, i.e., size()==0 |
boolean |
isFull()
Returns true if this cannot store any more elements without growing the heap, i.e., size()==capacity(). |
java.util.Iterator |
iterator()
|
int |
size()
Returns the number of elements in this. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public BinaryHeap(int maxSize)
public BinaryHeap(int maxSize, boolean resizable)
resizable
- true iff this should grow the heap to allow more
elementspublic BinaryHeap(java.lang.Comparable[] array)
BinaryHeap#currentSize
,
BinaryHeap#maxSize
Method Detail |
public void clear()
public java.lang.Comparable insert(java.lang.Comparable x)
public java.lang.Comparable getMax() throws java.util.NoSuchElementException
java.util.NoSuchElementException
public java.lang.Comparable extractMax() throws java.util.NoSuchElementException
java.util.NoSuchElementException
public java.util.Iterator iterator()
public int size()
public int capacity()
public boolean isFull()
public boolean isEmpty()
public java.lang.String toString()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |