Class EventHeap

  • All Implemented Interfaces:
    EventQueue

    public final class EventHeap
    extends Object
    implements EventQueue
    An implementation of EventQueue using an array-based heap.
    Author:
    Torsten Hildebrandt
    • Constructor Detail

      • EventHeap

        public EventHeap()
        Create an event heap with an initial capacity of 103.
      • EventHeap

        protected EventHeap​(EventHeap copyFrom)
        Copy constructor.
    • Method Detail

      • insert

        public void insert​(SimEvent x)
        insert an element, resize if necessary
        Specified by:
        insert in interface EventQueue
      • extract

        public SimEvent extract()
        Return and remove least element, or null if empty.
        Specified by:
        extract in interface EventQueue
      • indexOf

        public int indexOf​(SimEvent element)
        Scans the underlying array if it contains the given element. This methods requires O(n) time and compares object references for equality, not using equals().
        Parameters:
        element - the element to look for.
        Returns:
        the index of the element in the underlying array
      • remove

        public boolean remove​(SimEvent element)
        Removes an element from this heap. Required O(n) time to find the position of element in the underlying array.
        Specified by:
        remove in interface EventQueue
        Parameters:
        element - the element to remove
        Returns:
        true if the element was contained in the heap and successfully removed, false otherwise
      • clear

        public void clear()
        remove all elements *
      • size

        public int size()
        Return number of elements *
        Specified by:
        size in interface EventQueue