|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.jboss.util.Heap
Data structure that mantains data in a ordered binary tree; each node is greater (smaller) or equal than its 2 sub-nodes, for all the hierarchy.
Elements of this data structure should either implement Comparable, or a Comparator should be given as argument to the constructor.
Constructor Summary | |
Heap()
Creates a new Heap whose elements inserted implement the Comparable interface. |
|
Heap(java.util.Comparator comparator)
Creates a new Heap whose elements are compared using the given Comparator . |
Method Summary | |
void |
clear()
Empties this heap |
protected int |
compare(java.lang.Object o1,
java.lang.Object o2)
Compares the given objects using the comparator, if available, or considering them Comparable objects. |
java.lang.Object |
extract()
Removes and returns the least element of this heap. |
void |
insert(java.lang.Object obj)
Inserts the given element in this heap. |
protected int |
left(int index)
Returns the left child index of index . |
protected int |
parent(int index)
Returns the parent index of index . |
java.lang.Object |
peek()
Returns, without removing it, the least element of this heap. |
protected int |
right(int index)
Returns the right child index of index . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Heap()
Comparable
interface.public Heap(java.util.Comparator comparator)
Comparator
.Method Detail |
public void insert(java.lang.Object obj)
extract()
public java.lang.Object extract()
insert(java.lang.Object)
,
peek()
public java.lang.Object peek()
extract()
public void clear()
protected int compare(java.lang.Object o1, java.lang.Object o2)
java.lang.ClassCastException
- if nor the comparator is given
and nor both objects implements the Comparable interfaceprotected int parent(int index)
index
.protected int left(int index)
index
.protected int right(int index)
index
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |