heaps.event
Class EventHeap<T>

java.lang.Object
  extended by heaps.generic.GenericHeap<TimeAssociation<T>>
      extended by heaps.event.EventHeap<T>
Type Parameters:
T - the type of all timed heap elements
All Implemented Interfaces:
Heap<TimeAssociation<T>>
Direct Known Subclasses:
ArrayBackedEventHeap, BetweenHeap, FastEventHeap, LeafHeap, RootHeap

public abstract class EventHeap<T>
extends GenericHeap<TimeAssociation<T>>

An interface for all heaps that contain timers as their elements. This is done by extending interface GenericHeap such that all entries in the heap are TimeAssociation objects whose contained objects are of the parameterized type T. Implicitly, all implementations order the TimeAssociation elements by the comparator returned by static method TimeAssociation.getMinComparator. The running time of all methods defined by this interface depends on the backing implementation.

Author:
Michael Parker

Method Summary
abstract  boolean containsElement(T element)
          Returns whether there exists a TimeAssociation in the heap that is associated with the given element parameter.
abstract  TimeAssociation<T> getNextTime(T element)
          Returns the first TimeAssociation in the heap that is associated with the given element parameter.
abstract  TimeAssociation<T> removeNextTime(T element)
          Returns and removes the first TimeAssociation in the heap that is associated with the given element parameter.
abstract  boolean setNextTime(TimeAssociation<T> element, boolean do_add)
          Substitues the given parameter for the first TimeAssociation in the heap that is associated with the object returned by method getObject of the parameter.
 
Methods inherited from class heaps.generic.GenericHeap
add, allowsDuplicates, contains, getComparator, remove
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface heaps.Heap
clear, extract, getSize, isEmpty, top
 

Method Detail

setNextTime

public abstract boolean setNextTime(TimeAssociation<T> element,
                                    boolean do_add)
Substitues the given parameter for the first TimeAssociation in the heap that is associated with the object returned by method getObject of the parameter. Thus, if the object returned by method getObject is only present once in the heap, this method is equivalent to updating its time. If no such TimeAssociation object exists, this method has the same effect as calling method add(element) in interface GenericHeap if flag do_add is true; otherwise, this method returns false and has no effect.

Parameters:
element - the element to update in the heap
do_add - if true, then element will be added to the heap even if not already present
Returns:
if element was either updated or added

getNextTime

public abstract TimeAssociation<T> getNextTime(T element)
Returns the first TimeAssociation in the heap that is associated with the given element parameter. That is, of all the TimeAssociation elements that are associated with the given parameter, the one returned has the smallest value returned by method getTime. If no such element exists, this method returns null.

Parameters:
element - the element to query for in the list
Returns:
the first TimeAssociation whose event is equal to argument event, or null if none exists

containsElement

public abstract boolean containsElement(T element)
Returns whether there exists a TimeAssociation in the heap that is associated with the given element parameter.

Parameters:
element - the element to query for in the heap
Returns:
true if a TimeAssociation exists associated with element, false otheriwse

removeNextTime

public abstract TimeAssociation<T> removeNextTime(T element)
Returns and removes the first TimeAssociation in the heap that is associated with the given element parameter. That is, of all the TimeAssociation elements that are associated with the given parameter, the one removed has the smallest value returned by method getTime. If no such element exists, the heap remains unchanged and this method returns null.

Parameters:
element - the element to remove from the list
Returns:
the TimeAssociation that was removed from the heap, or null if the list remains unchanged