jist.runtime
Class Scheduler.Calendar

java.lang.Object
  extended by jist.runtime.Scheduler
      extended by jist.runtime.Scheduler.Calendar
Enclosing class:
Scheduler

static final class Scheduler.Calendar
extends Scheduler

Implementation of calendar queue event scheduler. See R.Brown. "Calendar queues: A fast O(1) priority queue implementation for the simulation event set problem." Comm. of ACM, 31(10):1220-1227, Oct 1988


Nested Class Summary
 
Nested classes/interfaces inherited from class jist.runtime.Scheduler
Scheduler.Calendar, Scheduler.Heap
 
Field Summary
private  long binMax
          Maximum time threshold of lastBin.
private  Scheduler.Heap[] bins
          Calendar days.
private  long binWidth
          Width of a single bin (length of a day).
private  int lastBin
          Last "day" where event was found.
private  int size
          Event queue size.
 
Constructor Summary
Scheduler.Calendar(long width, int nbins)
          Create a calendar scheduler with given number of bins and bin width.
 
Method Summary
private  int getBin(long time)
          Return mapped bin index for a given time.
 void insert(Event e)
          Insert event into event queue.
 boolean isEmpty()
          Return whether event queue is empty.
private  int minBin()
          Return bin with minimum time event -- linear scan.
private  int nextBin()
          Scan for and return next bin with an event with the next calendar year, or use minBin (above) to find bin with minimum event using direct search.
 Event peekFirst()
          Peek at first event in queue.
 Event removeFirst()
          Remove first event in queue.
 int size()
          Return size of event queue.
 
Methods inherited from class jist.runtime.Scheduler
clear, main
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bins

private Scheduler.Heap[] bins
Calendar days.


size

private int size
Event queue size.


lastBin

private int lastBin
Last "day" where event was found.


binWidth

private long binWidth
Width of a single bin (length of a day).


binMax

private long binMax
Maximum time threshold of lastBin.

Constructor Detail

Scheduler.Calendar

public Scheduler.Calendar(long width,
                          int nbins)
Create a calendar scheduler with given number of bins and bin width.

Parameters:
width - total width of all bins (length of a year)
nbins - number of bins (number of days in a year)
Method Detail

getBin

private int getBin(long time)
Return mapped bin index for a given time.

Parameters:
time - event time
Returns:
mapped bin index

minBin

private int minBin()
Return bin with minimum time event -- linear scan.

Returns:
bin with minimum time event

nextBin

private int nextBin()
Scan for and return next bin with an event with the next calendar year, or use minBin (above) to find bin with minimum event using direct search.

Returns:
mapped index of bin with next event

insert

public void insert(Event e)
Insert event into event queue.

Specified by:
insert in class Scheduler
Parameters:
e - event to insert

removeFirst

public Event removeFirst()
Remove first event in queue.

Specified by:
removeFirst in class Scheduler
Returns:
first event (removed) from queue

peekFirst

public Event peekFirst()
Peek at first event in queue.

Specified by:
peekFirst in class Scheduler
Returns:
first event (still) in queue

size

public int size()
Return size of event queue.

Specified by:
size in class Scheduler
Returns:
number of events in event queue

isEmpty

public boolean isEmpty()
Return whether event queue is empty.

Specified by:
isEmpty in class Scheduler
Returns:
whether event queue is empty