|
Jumpi v1.2.0 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.jumpi.impl.util.Heap
A heap-based priority queue, without any concurrency control (i.e., no blocking on empty/full states). This class provides the data structure mechanics for BoundedPriorityQueue.
The class currently uses a standard array-based heap, as described in, for example, Sedgewick's Algorithms text. All methods are fully synchronized. In the future, it may instead use structures permitting finer-grained locking.
[ Introduction to this package. ]
Field Summary | |
protected int |
capacity_
Initial capacity. |
protected int |
count_
Number of used slots. |
protected Comparable[] |
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. |
Method Summary | |
void |
clear()
Remove all elements. |
protected int |
compare(Comparable a,
Comparable b)
Perform element comparisons using comparator or natural ordering. |
Comparable |
extract()
Return and remove least element, or null if empty. |
void |
insert(Comparable x)
Insert an element, resize if necessary. |
protected int |
left(int k)
Return the index of the left child of a parent with the given index. |
protected int |
parent(int k)
Return the index in the heap of the parent of node at the given index. |
Comparable |
peek()
Return least element without removing it, or null if empty. |
protected int |
right(int k)
Return the index of the right child of a parent with the given index. |
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 Comparable[] nodes_
protected int count_
protected int capacity_
Constructor Detail |
public Heap(int capacity)
capacity
- the initial capacity.
java.lang.IllegalArgumentException
- when capacity smaller than or equal to
zero.Method Detail |
protected int compare(Comparable a, Comparable b)
a
- first object.b
- second object.
protected final int parent(int k)
k
- the child's index.
protected final int left(int k)
k
- the parent's index.
protected final int right(int k)
k
- the parent's index.
public void insert(Comparable x)
x
- the object to insert.
java.lang.IllegalArgumentException
- when x is null.public Comparable extract()
public Comparable peek()
public int size()
public void clear()
|
Jumpi v1.2.0 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |