A note on heapq module

Neil Cerutti horpner at yahoo.com
Thu Jan 18 08:23:57 EST 2007


On 2007-01-18, bearophileHUGS at lycos.com <bearophileHUGS at lycos.com> wrote:
> Neil Cerutti:
>> One more idea, cribbed from the linked list thread elsewhere:
>> it might be nice if your Heap could optionally use an
>> underlying collections.deque instead of a list. I don't know
>> how excellent Python's deque is, but it's possible a deque
>> would provide a faster heap than a contiguous array. C++'s
>> std::deque is the default implementation of C++'s
>> std::priority_queue for that reason (unless I'm confused
>> again).
>
> If you have some minutes you can do few speed tests and show us
> the code and the timing results...

I'll see what I can come up with. I'll have to test using the
native Python implementation, which should work with deque,
rather than the optimized C implementation, which doesn't. 

Unfortunately the inability to take advantage of the C
implementation of heapq might swamp any possible advantage of
using deque instead of list in a Heap class.

-- 
Neil Cerutti

-- 
Posted via a free Usenet account from http://www.teranews.com




More information about the Python-list mailing list