umontreal.iro.lecuyer.simevents.eventlist
Class RedblackTree
- java.lang.Object
-
- umontreal.iro.lecuyer.simevents.eventlist.RedblackTree
-
public class RedblackTree extends java.lang.Object implements EventList
An implementation ofEventListusing 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
TreeMapclass which implements a red black tree for general usage. This event list implementation is not efficient.
-
-
Constructor Summary
Constructors Constructor and Description RedblackTree()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidadd(Event ev)Adds a new event in the event list, according to the time of ev.voidaddAfter(Event ev, Event other)Same asadd, but adds the new event ev immediately after the event other in the list.voidaddBefore(Event ev, Event other)Same asadd, but adds the new event ev immediately before the event other in the list.voidaddFirst(Event ev)Adds a new event at the beginning of the event list.voidclear()Empties the event list, i.e., cancels all events.EventgetFirst()Returns the first event in the event list.<E extends Event>
EgetFirstOfClass(java.lang.Class<E> cl)Returns the first event of the class E (a subclass of Event) in the event list.EventgetFirstOfClass(java.lang.String cl)Returns the first event of the class cl (a subclass of Event) in the event list.booleanisEmpty()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.booleanremove(Event ev)Removes the event ev from the event list (cancels this event).EventremoveFirst()Removes the first event from the event list (to cancel or execute this event).java.lang.StringtoString()
-
-
-
Method Detail
-
clear
public void clear()
Description copied from interface:EventListEmpties the event list, i.e., cancels all events.
-
add
public void add(Event ev)
Description copied from interface:EventListAdds 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.
-
addFirst
public void addFirst(Event ev)
Description copied from interface:EventListAdds a new event at the beginning of the event list. The given event ev will occur at the current simulation time.
-
addBefore
public void addBefore(Event ev, Event other)
Description copied from interface:EventListSame asadd, but adds the new event ev immediately before the event other in the list.
-
addAfter
public void addAfter(Event ev, Event other)
Description copied from interface:EventListSame asadd, but adds the new event ev immediately after the event other in the list.
-
getFirst
public Event getFirst()
Description copied from interface:EventListReturns the first event in the event list. If the event list is empty, returns null.
-
getFirstOfClass
public Event getFirstOfClass(java.lang.String cl)
Description copied from interface:EventListReturns 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:
getFirstOfClassin interfaceEventList- Returns:
- the first event of class cl, or null if no such event exists in the list
-
getFirstOfClass
public <E extends Event> E getFirstOfClass(java.lang.Class<E> cl)
Description copied from interface:EventListReturns 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:
getFirstOfClassin interfaceEventList- Returns:
- the first event of class cl, or null if no such event exists in the list
-
remove
public boolean remove(Event ev)
Description copied from interface:EventListRemoves the event ev from the event list (cancels this event). Returns true if and only if the event removal has succeeded.
-
removeFirst
public Event removeFirst()
Description copied from interface:EventListRemoves 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:
removeFirstin interfaceEventList- Returns:
- the first event removed from the list, or null if the list is empty
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
iterator
public java.util.Iterator<Event> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<Event>
-
listIterator
public java.util.ListIterator<Event> listIterator()
Description copied from interface:EventListReturns a list iterator over the elements of the class Event in this list.- Specified by:
listIteratorin interfaceEventList- Returns:
- a list iterator over the elements of the class Event in this list
-
-
DMelt 3.0 © DataMelt by jWork.ORG