SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
umontreal.ssj.simevents.eventlist.RedblackTree Class Reference

An implementation of EventList using a red black tree, which is similar to a binary search tree except that every node is colored red or black. More...

Inheritance diagram for umontreal.ssj.simevents.eventlist.RedblackTree:
umontreal.ssj.simevents.eventlist.EventList

Public Member Functions

void clear ()
 Empties the event list, i.e., cancels all events.
void add (Event ev)
 Adds a new event in the event list, according to the time of ev.
void addFirst (Event ev)
 Adds a new event at the beginning of the event list.
void addBefore (Event ev, Event other)
 Same as add, but adds the new event ev immediately before the event other in the list.
void addAfter (Event ev, Event other)
 Same as add, but adds the new event ev immediately after the event other in the list.
Event getFirst ()
 Returns the first event in the event list.
Event getFirstOfClass (String cl)
 Returns the first event of the class cl (a subclass of Event) in the event list.
boolean remove (Event ev)
 Removes the event ev from the event list (cancels this event).
Event removeFirst ()
 Removes the first event from the event list (to cancel or execute this event).
ListIterator< EventlistIterator ()
 Returns a list iterator over the elements of the class Event in this list.
boolean isEmpty ()
 Returns true if and only if the event list is empty (no event is scheduled).

Package Functions

public< E extends Event > E getFirstOfClass (Class< E > cl)
 Returns the first event of the class E (a subclass of Event) in the event list.

Detailed Description

An implementation of EventList using a red black tree, which is similar to a binary search tree except that every node is colored red or black.

When modifying the structure, the tree is reorganized for the colors to satisfy rules that give an average \(O(\log(n))\) time for removing the first event or inserting a new event, where \(n\) is the number of elements in the structure. However, adding or removing events imply reorganizing the tree and requires more overhead than a binary search tree.

The present implementation uses the Java 2 TreeMap class which implements a red black tree for general usage. This event list implementation is not efficient.

Definition at line 52 of file RedblackTree.java.

Member Function Documentation

◆ add()

void umontreal.ssj.simevents.eventlist.RedblackTree.add ( Event ev)

Adds a new event in the event list, according to the time of ev.

If the event list contains events scheduled to happen at the same time as ev, ev must be added after all these events.

Parameters
evevent to be added

Implements umontreal.ssj.simevents.eventlist.EventList.

Definition at line 67 of file RedblackTree.java.

◆ addAfter()

void umontreal.ssj.simevents.eventlist.RedblackTree.addAfter ( Event ev,
Event other )

Same as add, but adds the new event ev immediately after the event other in the list.

Parameters
evevent to be added
otherreference event after which ev will be added

Implements umontreal.ssj.simevents.eventlist.EventList.

Definition at line 93 of file RedblackTree.java.

◆ addBefore()

void umontreal.ssj.simevents.eventlist.RedblackTree.addBefore ( Event ev,
Event other )

Same as add, but adds the new event ev immediately before the event other in the list.

Parameters
evevent to be added
otherreference event before which ev will be added

Implements umontreal.ssj.simevents.eventlist.EventList.

Definition at line 85 of file RedblackTree.java.

◆ addFirst()

void umontreal.ssj.simevents.eventlist.RedblackTree.addFirst ( Event ev)

Adds a new event at the beginning of the event list.

The given event ev will occur at the current simulation time.

Parameters
evevent to be added

Implements umontreal.ssj.simevents.eventlist.EventList.

Definition at line 76 of file RedblackTree.java.

◆ clear()

void umontreal.ssj.simevents.eventlist.RedblackTree.clear ( )

Empties the event list, i.e., cancels all events.

Implements umontreal.ssj.simevents.eventlist.EventList.

Definition at line 56 of file RedblackTree.java.

◆ getFirst()

Event umontreal.ssj.simevents.eventlist.RedblackTree.getFirst ( )

Returns the first event in the event list.

If the event list is empty, returns null.

Returns
the first event in the event list, or null if the list is empty

Implements umontreal.ssj.simevents.eventlist.EventList.

Definition at line 101 of file RedblackTree.java.

◆ getFirstOfClass() [1/2]

public< E extends Event > E umontreal.ssj.simevents.eventlist.RedblackTree.getFirstOfClass ( Class< E > cl)
package

Returns the first event of the class E (a subclass of Event) in the event list.

If no such event is found, returns null.

Returns
the first event of class cl, or null if no such event exists in the list

Implements umontreal.ssj.simevents.eventlist.EventList.

Definition at line 116 of file RedblackTree.java.

◆ getFirstOfClass() [2/2]

Event umontreal.ssj.simevents.eventlist.RedblackTree.getFirstOfClass ( String cl)

Returns the first event of the class cl (a subclass of Event) in the event list.

If no such event is found, returns null.

Returns
the first event of class cl, or null if no such event exists in the list

Implements umontreal.ssj.simevents.eventlist.EventList.

Definition at line 105 of file RedblackTree.java.

◆ isEmpty()

boolean umontreal.ssj.simevents.eventlist.RedblackTree.isEmpty ( )

Returns true if and only if the event list is empty (no event is scheduled).

Returns
true if the event list is empty

Implements umontreal.ssj.simevents.eventlist.EventList.

Definition at line 172 of file RedblackTree.java.

◆ listIterator()

ListIterator< Event > umontreal.ssj.simevents.eventlist.RedblackTree.listIterator ( )

Returns a list iterator over the elements of the class Event in this list.

Returns
a list iterator over the elements of the class Event in this list

Implements umontreal.ssj.simevents.eventlist.EventList.

Definition at line 168 of file RedblackTree.java.

◆ remove()

boolean umontreal.ssj.simevents.eventlist.RedblackTree.remove ( Event ev)

Removes the event ev from the event list (cancels this event).

Returns true if and only if the event removal has succeeded.

Parameters
evevent to be removed
Returns
true if the event was successfully removed from the list

Implements umontreal.ssj.simevents.eventlist.EventList.

Definition at line 127 of file RedblackTree.java.

◆ removeFirst()

Event umontreal.ssj.simevents.eventlist.RedblackTree.removeFirst ( )

Removes the first event from the event list (to cancel or execute this event).

Returns the removed event. If the list is empty, then null is returned.

Returns
the first event removed from the list, or null if the list is empty

Implements umontreal.ssj.simevents.eventlist.EventList.

Definition at line 139 of file RedblackTree.java.


The documentation for this class was generated from the following file: