Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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?

In reply to Data Structure needed for Event Queue by vaevictus

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • 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> <u> <ul>
  • 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 intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2022-05-22 15:18 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (80 votes). Check out past polls.