public class SplayTree extends java.lang.Object implements EventList
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 and Description |
|---|
SplayTree() |
| Modifier and Type | Method and Description |
|---|---|
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> |
getFirstOfClass(java.lang.Class<E> cl)
Returns the first event of the class E (a subclass of
Event) in the event list.
|
Event |
getFirstOfClass(java.lang.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).
|
java.util.Iterator<Event> |
iterator() |
java.util.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).
|
java.lang.String |
toString() |
public boolean isEmpty()
EventListpublic void clear()
EventListpublic void add(Event ev)
EventListpublic void addFirst(Event ev)
EventListpublic void addBefore(Event ev, Event other)
EventListadd, but adds the new event ev
immediately before the event other in the list.public void addAfter(Event ev, Event other)
EventListadd, but adds the new event ev
immediately after the event other in the list.public Event getFirst()
EventListpublic Event getFirstOfClass(java.lang.String cl)
EventListgetFirstOfClass in interface EventListpublic <E extends Event> E getFirstOfClass(java.lang.Class<E> cl)
EventListgetFirstOfClass in interface EventListpublic java.util.Iterator<Event> iterator()
iterator in interface java.lang.Iterable<Event>public java.util.ListIterator<Event> listIterator()
EventListlistIterator in interface EventListpublic boolean remove(Event ev)
EventListpublic Event removeFirst()
EventListremoveFirst in interface EventListpublic java.lang.String toString()
toString in class java.lang.ObjectTo submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.