vaevictus has asked for the wisdom of the Perl Monks concerning the following question:
I'm working on a game, and I need to give it a time based event queue.
I'm concerned about efficiency, to an extent.
Here are my problems:
- events might be very far apart, but could also be on the *exact* same time.
- I'm wanting to be able to cancel out events.
- I'd two simple interfaces, push($time,$eventref), and $eventref=pop(); which returns one of the events from the lowest $time.
- It seems to me that a comparison tree, or a ternary tree would be fine, but haven't found any that would be appropriate to use over just coding this by hand.
Array of Arrays seems inefficient when the nodes are very far apart, requiring lots of iteration, and i'm not so sure how it would scale when i've inserted and removed millions of events.
Hashes of Arrays seems better about most things, but requires a expensive sort every pop(), or possibly a sort upon each new timestamp needed, if you store the "lowest" somewhere.
I'm sure TMTOWTDI.
Any modules out there that might help out?
Or, any suggestions on how to do this efficiently?
Back to
Seekers of Perl Wisdom