I'm trying to decide what container to use for an event scheduler. The requirements I'm trying to satisfy are:
- Events should be ordered by time, and are evaluated by getting the front of the scheduler, evaluating the event, and then deleting the front.
- Events can be inserted for any time (scheduled to be evaluated at any time in the future).
- It should be possible to have a pointer to an event that isn't changed if other elements are added to the scheduler. For example, while evaluating the current event, it may be necessary to also delete a future event. Knowledge about this future event should be implemented as a pointer.
- It should be possible to reschedule events, e.g. change their time to a future time.
What containers are possible?
- STL queue - does not allow events to be inserted anywhere (e.g. by time).
- STL vector - inserting new events into the vector can break pointers to existing events.
- STL list -
events are constant after constructing, so rescheduling is not possible except by deleting an existing event and then creating a new one at a later time.Edit: confused this with STL set.
Are there other options? I have read that it is not generally recommended to create your own containers (e.g. linked lists) for efficiency.
Thanks for your advice!
Edit
From the comments, two further suggestions:
- STL set - elements are constant after inserting.
- STL priority_queue - depending on the choice of STL container (vector or deque), this can preserve pointers (deque does) after inserting, but only if inserting at either end. However, elements are constant after inserting.