Package jasima.core.simulation
Class EventHeap
- java.lang.Object
-
- jasima.core.simulation.EventHeap
-
- All Implemented Interfaces:
EventQueue
public final class EventHeap extends Object implements EventQueue
An implementation ofEventQueueusing an array-based heap.- Author:
- Torsten Hildebrandt
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ArrayList<SimEvent>allEvents()Returns all events as an ordered list.voidclear()remove all elements *SimEventextract()Return and remove least element, or null if empty.intindexOf(SimEvent element)Scans the underlying array if it contains the given element.voidinsert(SimEvent x)insert an element, resize if necessarybooleanremove(SimEvent element)Removes an element from this heap.intsize()Return number of elements *
-
-
-
Constructor Detail
-
EventHeap
public EventHeap()
Create an event heap with an initial capacity of 103.
-
EventHeap
public EventHeap(int capacity) throws IllegalArgumentExceptionCreate an event heap with the given capacity.- Throws:
IllegalArgumentException- if capacity less or equal to zero
-
EventHeap
protected EventHeap(EventHeap copyFrom)
Copy constructor.
-
-
Method Detail
-
insert
public void insert(SimEvent x)
insert an element, resize if necessary- Specified by:
insertin interfaceEventQueue
-
extract
public SimEvent extract()
Return and remove least element, or null if empty.- Specified by:
extractin interfaceEventQueue
-
indexOf
public int indexOf(SimEvent element)
Scans the underlying array if it contains the given element. This methods requires O(n) time and compares object references for equality, not usingequals().- Parameters:
element- the element to look for.- Returns:
- the index of the element in the underlying array
-
remove
public boolean remove(SimEvent element)
Removes an element from this heap. Required O(n) time to find the position ofelementin the underlying array.- Specified by:
removein interfaceEventQueue- Parameters:
element- the element to remove- Returns:
trueif the element was contained in the heap and successfully removed,falseotherwise
-
clear
public void clear()
remove all elements *
-
size
public int size()
Return number of elements *- Specified by:
sizein interfaceEventQueue
-
allEvents
public ArrayList<SimEvent> allEvents()
Returns all events as an ordered list.- Specified by:
allEventsin interfaceEventQueue- Returns:
- All events.
-
-