You can either go with heap queue, as @Bogdan suggests, or you can use sched for more advance purposes.
Event list data structure in python
-
01-07-2022 - |
Pergunta
I need to implement an event list in python, where each element is an event that has an associated timestamps. The actions that I need to perform are essentially two: inserting in the right order (decreasing timestamps), and retrieving the event with the smaller start time.
I am aware of the bisect module, but it doesn't allow to insert arbitrary items in the list. For this reason I think that maybe I could implement the event list with two different python data structures:
- a bisect list containing all the timestamps
- a dictionary with the timestamps as the keys ans the events as value
Inserting and retrieving are straightforward.
Do you think that there is a more efficient approach?
Solução
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow