Package EDU.oswego.cs.dl.util.concurrent
Class Heap
java.lang.Object
EDU.oswego.cs.dl.util.concurrent.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.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionHeap
(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
Modifier and TypeMethodDescriptionvoid
clear()
remove all elementsprotected int
perform element comaprisons using comparator or natural orderingextract()
Return and remove least element, or null if emptyvoid
insert an element, resize if necessaryprotected final int
left
(int k) protected final int
parent
(int k) peek()
Return least element without removing it, or null if emptyprotected final int
right
(int k) int
size()
Return number of elements
-
Field Details
-
nodes_
-
count_
protected int count_ -
cmp_
-
-
Constructor Details
-
Heap
Create a Heap with the given initial capacity and comparator- Throws:
IllegalArgumentException
- if capacity less or equal to zero
-
Heap
public Heap(int capacity) Create a Heap with the given capacity, and relying on natural ordering.
-
-
Method Details
-
compare
perform element comaprisons using comparator or natural ordering -
parent
protected final int parent(int k) -
left
protected final int left(int k) -
right
protected final int right(int k) -
insert
insert an element, resize if necessary -
extract
Return and remove least element, or null if empty -
peek
Return least element without removing it, or null if empty -
size
public int size()Return number of elements -
clear
public void clear()remove all elements
-