in reply to Re: Re: Re: Re: Re: looking for a Priority Queue
in thread looking for a Priority Queue

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

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re: looking for a Priority Queue
by educated_foo (Vicar) on May 07, 2002 at 16:08 UTC
    now Heap::Priority on CPAN - when it gets listed

    This name would be very confusing. People would think either "heap" or "priority queue" in the textbook form of a heap-ordered binary tree. While your module will appear to do something similar, it doesn't have O(log(n)) performance when dealing with n items with n different priorities. At the very least, it should be stated prominently in the POD that inserting n items with different priorities is O(n^2 log n). I would prefer to see it under a different name.

    btw, here's FOLDOC's definition of a heap (sense 2).

    /s