I am trying to create a hip of event. Thus, I have define a class Event
which is inherited by my different events.
class Event:
def __init__(self, last_instant):
self.last_instant = last_instant # That's the prio criteria
class Event1(Event):
def __init__(self, last_instant, value):
Event.__init__(self, last_instant)
self.value = value
class Event2(Event):
...
The value last_instant
is the prio criteria, thus the heap is composed of tuples defined as follows:
(last_instant, Event)
However, I have events that are placed at the same last_instant
, thus the heapq
looks for the <
implementation in the Event
. I didn't yet implement it, but even if I did, I simply don't know how since some of the events do not have any criteria to differentiate which should be popped first from the heap.
How can I implement a heap where the order doesn't matter if the last_instant
is the same?
On the other hand, if I have event of the same type (same class) at the same instant (same prio), I want to pop them together and treat them simultaneously.
The best way to achieve this that I can see is to pop all items at the same instant, store them in a list, and then treat them sequentially. Then go to the next instant. However, it doesn't seems compatible with heapq.
Thanks!