Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

alma::ACS::jbaci::Heap Class Reference

List of all members.

Public Member Functions

 Heap (int capacity, Comparator cmp) throws IllegalArgumentException
 Heap (int capacity)
synchronized void insert (Object x)
synchronized Object extract ()
synchronized Object peek ()
synchronized int size ()
synchronized void clear ()

Protected Member Functions

int compare (Object a, Object b)
final int parent (int k)
final int left (int k)
final int right (int k)

Protected Attributes

Object[] nodes_
int count_ = 0
final Comparator cmp_

Detailed Description

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.


Constructor & Destructor Documentation

alma::ACS::jbaci::Heap::Heap int  capacity,
Comparator  cmp
throws IllegalArgumentException [inline]
 

Create a Heap with the given initial capacity and comparator

Parameters:
capacity initial capacity.
cmp comparator instance.
Exceptions:
IllegalArgumentException if capacity less or equal to zero

alma::ACS::jbaci::Heap::Heap int  capacity  )  [inline]
 

Create a Heap with the given capacity, and relying on natural ordering.

Parameters:
capacity initial capacity.


Member Function Documentation

synchronized void alma::ACS::jbaci::Heap::clear  )  [inline]
 

Remove all elements.

int alma::ACS::jbaci::Heap::compare Object  a,
Object  b
[inline, protected]
 

Perform element comparisons using comparator or natural ordering.

synchronized Object alma::ACS::jbaci::Heap::extract  )  [inline]
 

Return and remove least element, or null if empty.

Returns:
extraced least element.

synchronized void alma::ACS::jbaci::Heap::insert Object  x  )  [inline]
 

Insert an element, resize if necessary.

Parameters:
x object to insert.

final int alma::ACS::jbaci::Heap::left int  k  )  [inline, protected]
 

Get left child.

final int alma::ACS::jbaci::Heap::parent int  k  )  [inline, protected]
 

Get parent index.

synchronized Object alma::ACS::jbaci::Heap::peek  )  [inline]
 

Return least element without removing it, or null if empty.

Returns:
least element.

final int alma::ACS::jbaci::Heap::right int  k  )  [inline, protected]
 

Get right child.

synchronized int alma::ACS::jbaci::Heap::size  )  [inline]
 

Return number of elements.

Returns:
number of elements.


Member Data Documentation

final Comparator alma::ACS::jbaci::Heap::cmp_ [protected]
 

Ordering comparator.

int alma::ACS::jbaci::Heap::count_ = 0 [protected]
 

Number of used slots.

Object [] alma::ACS::jbaci::Heap::nodes_ [protected]
 

The tree nodes, packed into an array.


The documentation for this class was generated from the following file:
Generated on Thu Apr 30 02:53:29 2009 for ACS Java API by doxygen 1.3.8