package ProGAL.dataStructures;
/**
* 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. ]
**/
public class Heap {
protected Object[] nodes; // tree nodes, packed into an array
protected int count = 0; // number of used slots
protected SortTool tool; // for ordering
/* ****************************************************************************
* Creates a heap with the given initial capacity and with the given SortTool
* @exception IllegalArgumentException if capacity less or equal to zero.
******************************************************************************/
public Heap(int capacity, SortTool tool)
throws IllegalArgumentException {
if (capacity < 0) capacity = 0;
nodes = new Object[capacity];
this.tool = tool;
}
/*
* Creates a heap with the given capacity, and relying on natural ordering.
*/
public Heap(int capacity) { this(capacity, null); }
/*
* Creates a heap of the given set in O(n) time, with the given SortTool
*/
public Heap(Set