/// <summary> /// Compare two events /// </summary> /// <param name="a">First event</param> /// <param name="b">Second event</param> /// <returns></returns> public static int Compare(Event a, Event b) { // check for nulls if(a == null) return b == null ? 0 : -1; else if (b == null) return 1; if (a.Time == b.Time) return 0; else return a.Time > b.Time ? 1 : -1; }
/// <summary> /// Add an event to the queue /// </summary> /// <param name="evt"></param> public void Enqueue(Event evt) { Simulation.CollectStats(); Queue.Enqueue(evt); MaxQueueLength = Math.Max(Queue.Count, MaxQueueLength); }
/// <summary> /// Put a new event into the event queue /// </summary> /// <param name="evt">Event</param> public static void RegisterEvent(Event evt) { if (evt != null) { // traverse the queue and find the first element bigger than current var idx = 0; foreach (var curr in EventQueue) { // there's a place to add the event to if(curr.Time > evt.Time) { EventQueue.Insert(idx, evt); return; } idx++; } EventQueue.Add(evt); } }