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?
Are you posting in the right place? Check out Where do I post X? to know for sure.
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
Want more info? How to link or
or How to display code and escape characters
are good places to start.