Hi you are of course correct and incorrect. The algorithm implemented by this module (now Heap::Priority on CPAN - when it gets listed) assumes that the item count >> number of priority levels.

I have improved the priority level sort efficiency so that all that happens is that a new priority level is sorted to its correct place which is O(n) rather than the less efficient way it was done.

As it currently stands it will add() and pop() 100,000 items into 100 different levels in 9 seconds or into 1000 levels in 40 seconds. Yes that is definitely a geometric decay as the number of priority levels go up....

use Heap::Priority; my $n = 100000; my $start = time; my $h = new Heap::Priority; $h->add($_, $_%1000) for 1..$n; $h->pop for 1..$n; print "Did $n in ", time - $start, " seconds"; __DATA__ Did 100000 in 40 seconds

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: Re: Re: Re: Re: Re: looking for a Priority Queue by tachyon
in thread looking for a Priority Queue by newatperl

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.