peersim.edsim
Class Heap

java.lang.Object
  extended by peersim.edsim.Heap
All Implemented Interfaces:
PriorityQ

public class Heap
extends java.lang.Object
implements PriorityQ

The Heap data structure used to maintain events "sorted" by scheduled time and to obtain the next event to be executed.


Nested Class Summary
 
Nested classes/interfaces inherited from interface peersim.edsim.PriorityQ
PriorityQ.Event
 
Parameter Summary
pbits
          This parameter specifies how many bits are used to order events that occur at the same time.
size
          Specifies the initial capacity of the heap.
 
Constructor Summary
Heap()
          Initializes a new heap using defaults.
Heap(java.lang.String prefix)
          Initializes a new heap using the configuration.
 
Method Summary
 void add(long time, java.lang.Object event, Node node, byte pid)
          Add a new event, to be scheduled at the specified time.
 void add(long time, java.lang.Object event, Node node, byte pid, long priority)
          Add a new event, to be scheduled at the specified time.
 long maxPriority()
          Maximal value of priority this interpretation can deal with.
 long maxTime()
          Maximal value of time this interpretation can represent.
 PriorityQ.Event removeFirst()
          Removes the first event in the heap and returns it.
 int size()
          Returns the current number of events in the system.
 java.lang.String toString()
          Prints the time values contained in the heap.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Parameter Detail

pbits

This parameter specifies how many bits are used to order events that occur at the same time. Defaults to 8. A value smaller than 8 causes an IllegalParameterException. Higher values allow for a better discrimination, but reduce the maximal time steps that can be simulated.


size

Specifies the initial capacity of the heap. Defaults to 65536.

Constructor Detail

Heap

public Heap()
Initializes a new heap using defaults.


Heap

public Heap(java.lang.String prefix)
Initializes a new heap using the configuration.

Method Detail

size

public int size()
Returns the current number of events in the system.

Specified by:
size in interface PriorityQ

add

public void add(long time,
                java.lang.Object event,
                Node node,
                byte pid)
Add a new event, to be scheduled at the specified time.

Specified by:
add in interface PriorityQ
Parameters:
time - the time at which this event should be scheduled
event - the object describing the event
node - the node at which the event has to be delivered
pid - the protocol that handles the event

add

public void add(long time,
                java.lang.Object event,
                Node node,
                byte pid,
                long priority)
Add a new event, to be scheduled at the specified time.

Specified by:
add in interface PriorityQ
Parameters:
time - the time at which this event should be scheduled
event - the object describing the event
node - the node at which the event has to be delivered
pid - the protocol that handles the event
priority - if for two events the "time" value is the same, this value should be used to order them. Lower value means higher priority. Like with time, non-negativity as assumed.

removeFirst

public PriorityQ.Event removeFirst()
Removes the first event in the heap and returns it. Note that, to avoid garbage collection, a singleton instance of the Event class is used. This means that data contained in the returned event are overwritten when a new invocation of this method is performed.

Specified by:
removeFirst in interface PriorityQ
Returns:
first event or null if size is zero

maxTime

public long maxTime()
Description copied from interface: PriorityQ
Maximal value of time this interpretation can represent.

Specified by:
maxTime in interface PriorityQ

maxPriority

public long maxPriority()
Description copied from interface: PriorityQ
Maximal value of priority this interpretation can deal with. That is, the number of different priority levels is maxPriority()+1 because 0 is also a valid level.

Specified by:
maxPriority in interface PriorityQ
See Also:
PriorityQ.add(long,Object,Node,byte,long)

toString

public java.lang.String toString()
Prints the time values contained in the heap.

Overrides:
toString in class java.lang.Object