|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.cosylab.epics.caj.util.Heap
public class Heap
A heap-based priority queue. The class currently uses a standard array-based heap, as described in, for example, Sedgewick's Algorithms text. All methods are fully synchronized.
| Field Summary | |
|---|---|
protected Comparator |
cmp_
Ordering comparator. |
protected int |
count_
Number of used slots. |
protected Object[] |
nodes_
The tree nodes, packed into an array. |
| Constructor Summary | |
|---|---|
Heap(int capacity)
Create a Heap with the given capacity, and relying on natural ordering. |
|
Heap(int capacity,
Comparator cmp)
Create a Heap with the given initial capacity and comparator |
|
| Method Summary | |
|---|---|
void |
clear()
Remove all elements. |
protected int |
compare(Object a,
Object b)
Perform element comparisons using comparator or natural ordering. |
Object |
extract()
Return and remove least element, or null if empty. |
void |
insert(Object x)
Insert an element, resize if necessary. |
protected int |
left(int k)
Get left child. |
protected int |
parent(int k)
Get parent index. |
Object |
peek()
Return least element without removing it, or null if empty. |
protected int |
right(int k)
Get right child. |
int |
size()
Return number of elements. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected Object[] nodes_
protected int count_
protected final Comparator cmp_
| Constructor Detail |
|---|
public Heap(int capacity,
Comparator cmp)
throws IllegalArgumentException
capacity - initial capacity.cmp - comparator instance.
IllegalArgumentException - if capacity less or equal to zeropublic Heap(int capacity)
capacity - initial capacity.| Method Detail |
|---|
protected int compare(Object a,
Object b)
protected final int parent(int k)
protected final int left(int k)
protected final int right(int k)
public void insert(Object x)
x - object to insert.public Object extract()
public Object peek()
public int size()
public void clear()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||