SSJ
V. 2.6.

umontreal.iro.lecuyer.simevents.eventlist
Class SplayTree

java.lang.Object
  extended by umontreal.iro.lecuyer.simevents.eventlist.SplayTree
All Implemented Interfaces:
Iterable<Event>, EventList

public class SplayTree
extends Object
implements EventList

An implementation of EventList using a splay tree. This tree is like a binary search tree except that when it is modified, the affected node is moved to the top. The rebalancing scheme is simpler than for a red black tree and can avoid the worst case of the linked list. This gives a O(log(n)) average time for adding or removing an event, where n is the size of the event list.


Constructor Summary
SplayTree()
           
 
Method Summary
 void add(Event ev)
          Adds a new event in the event list, according to the time of ev.
 void addAfter(Event ev, Event other)
          Same as add, but adds the new event ev immediately after the event other in the 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 addFirst(Event ev)
          Adds a new event at the beginning of the event list.
 void clear()
          Empties the event list, i.e., cancels all events.
 Event getFirst()
          Returns the first event in the event list.
<E extends Event>
E
getFirstOfClass(Class<E> cl)
          Returns the first event of the class E (a subclass of 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 isEmpty()
          Returns true if and only if the event list is empty (no event is scheduled).
 Iterator<Event> iterator()
           
 ListIterator<Event> listIterator()
          Returns a list iterator over the elements of the class Event in this 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).
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SplayTree

public SplayTree()
Method Detail

isEmpty

public boolean isEmpty()
Description copied from interface: EventList
Returns true if and only if the event list is empty (no event is scheduled).

Specified by:
isEmpty in interface EventList
Returns:
true if the event list is empty

clear

public void clear()
Description copied from interface: EventList
Empties the event list, i.e., cancels all events.

Specified by:
clear in interface EventList

add

public void add(Event ev)
Description copied from interface: EventList
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.

Specified by:
add in interface EventList
Parameters:
ev - event to be added

addFirst

public void addFirst(Event ev)
Description copied from interface: EventList
Adds a new event at the beginning of the event list. The given event ev will occur at the current simulation time.

Specified by:
addFirst in interface EventList
Parameters:
ev - event to be added

addBefore

public void addBefore(Event ev,
                      Event other)
Description copied from interface: EventList
Same as add, but adds the new event ev immediately before the event other in the list.

Specified by:
addBefore in interface EventList
Parameters:
ev - event to be added
other - reference event before which ev will be added

addAfter

public void addAfter(Event ev,
                     Event other)
Description copied from interface: EventList
Same as add, but adds the new event ev immediately after the event other in the list.

Specified by:
addAfter in interface EventList
Parameters:
ev - event to be added
other - reference event after which ev will be added

getFirst

public Event getFirst()
Description copied from interface: EventList
Returns the first event in the event list. If the event list is empty, returns null.

Specified by:
getFirst in interface EventList
Returns:
the first event in the event list, or null if the list is empty

getFirstOfClass

public Event getFirstOfClass(String cl)
Description copied from interface: EventList
Returns the first event of the class cl (a subclass of Event) in the event list. If no such event is found, returns null.

Specified by:
getFirstOfClass in interface EventList
Returns:
the first event of class cl, or null if no such event exists in the list

getFirstOfClass

public <E extends Event> E getFirstOfClass(Class<E> cl)
Description copied from interface: EventList
Returns the first event of the class E (a subclass of Event) in the event list. If no such event is found, returns null.

Specified by:
getFirstOfClass in interface EventList
Returns:
the first event of class cl, or null if no such event exists in the list

iterator

public Iterator<Event> iterator()
Specified by:
iterator in interface Iterable<Event>

listIterator

public ListIterator<Event> listIterator()
Description copied from interface: EventList
Returns a list iterator over the elements of the class Event in this list.

Specified by:
listIterator in interface EventList
Returns:
a list iterator over the elements of the class Event in this list

remove

public boolean remove(Event ev)
Description copied from interface: EventList
Removes the event ev from the event list (cancels this event). Returns true if and only if the event removal has succeeded.

Specified by:
remove in interface EventList
Parameters:
ev - event to be removed
Returns:
true if the event was successfully removed from the list

removeFirst

public Event removeFirst()
Description copied from interface: EventList
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.

Specified by:
removeFirst in interface EventList
Returns:
the first event removed from the list, or null if the list is empty

toString

public String toString()
Overrides:
toString in class Object

SSJ
V. 2.6.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.