A note on heapq module

Steven Bethard steven.bethard at gmail.com
Thu Jan 18 18:41:48 EST 2007


bearophileHUGS at lycos.com wrote:
> Steven Bethard wrote:
>> The current code fails when using unbound methods however::
> 
> I don't like your solution, this class was already slow enough. Don't
> use unbound methods with this class :-)
> Maybe there's a (better) solution to your problem: to make Heap a
> function (or classmethod) that return sone of two possibile objects
> created by one of two different classes that have different methods...

That's probably viable.  Maybe you should just have two separate 
classes: Heap and KeyedHeap.  The inplace= parameter doesn't really make 
sense for a KeyedHeap anway, so you could just have::

     Heap(sequence=None, inplace=False)
     KeyedHeap(key, sequence=None)

Of course, this approach ends up with a bunch of code duplication again.

STeVe



More information about the Python-list mailing list