Package org.epics.ca.impl.search
Class SearchTimer.Heap
- java.lang.Object
-
- org.epics.ca.impl.search.SearchTimer.Heap
-
- Enclosing class:
- SearchTimer
public class SearchTimer.Heap extends java.lang.ObjectA 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.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Remove all elements.protected intcompare(java.lang.Object a, java.lang.Object b)Perform element comparisons using comparator or natural ordering.java.lang.Objectextract()Return and remove least element, or null if empty.java.lang.Object[]getNodes()voidinsert(java.lang.Object x)Insert an element, resize if necessary.protected intleft(int k)Get left child.protected intparent(int k)Get parent index.java.lang.Objectpeek()Return least element without removing it, or null if empty.protected intright(int k)Get right child.intsize()Return number of elements.
-
-
-
Constructor Detail
-
Heap
public Heap(int capacity, java.util.Comparator cmp) throws java.lang.IllegalArgumentExceptionCreate a Heap with the given initial capacity and comparator- Parameters:
capacity- initial capacity.cmp- comparator instance.- Throws:
java.lang.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.- Parameters:
capacity- initial capacity.
-
-
Method Detail
-
compare
protected int compare(java.lang.Object a, java.lang.Object b)Perform element comparisons using comparator or natural ordering.- Parameters:
a- the first object to compare.b- the second object to compare.- Returns:
- the comparison result.
-
parent
protected final int parent(int k)
Get parent index.- Parameters:
k- k- Returns:
- number
-
left
protected final int left(int k)
Get left child.- Parameters:
k- k- Returns:
- number
-
right
protected final int right(int k)
Get right child.- Parameters:
k- k- Returns:
- number
-
insert
public void insert(java.lang.Object x)
Insert an element, resize if necessary.- Parameters:
x- object to insert.
-
extract
public java.lang.Object extract()
Return and remove least element, or null if empty.- Returns:
- extracted least element.
-
peek
public java.lang.Object peek()
Return least element without removing it, or null if empty.- Returns:
- least element.
-
size
public int size()
Return number of elements.- Returns:
- number of elements.
-
clear
public void clear()
Remove all elements.
-
getNodes
public java.lang.Object[] getNodes()
-
-