This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author scoder
Recipients
Date 2005-03-13.10:45:15
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Bug 1158313 (requesting functions for heap iteration)
was rejected, one of the reasons being that iteration
does not fit well with the module design providing
helper functions.

Here is an implementation of a Heap class for that
module that encapsulates a list. It supports iteration
as well as the usual keyword arguments passed to sort()
or sorted(): key, cmp, reversed. It further supports
skipping the heapify step (heapify=True/False) when
constructing the heap as well as copying the list if
unnecessary (copy=True/False). The latter is generally
discouraged and not the default. It is, however, useful
for one-shot sequence generation as in

>>> h = Heap([ random() for i in range(1000) ], copy=False)

A further feature (somewhat obvious for heaps) is that
iteration is not interrupted by items being pushed on
the heap, they are simply integrated.

"heapreplace" is supported by a "pushpop" function as
initially proposed by R. Hettinger. It always returns
the smallest item, also considering the one being pushed.

This implementation is complementary to the existing
functions that work on arbitrary (mutable) sequences.
Both have their use cases and both make sense in the
module. The Heap class has the additional advantage of
encapsulating the list and thus allowing to support
special item comparisons in a consistent way.

There is not yet any documentation or unit tests, but
they should be easy to write once the Heap class is
actually considered for integration.
History
Date User Action Args
2007-08-23 15:42:11adminlinkissue1162363 messages
2007-08-23 15:42:11admincreate