Raymond Hettinger
39659f22fa
Issue #19018 : The heapq.merge() function no longer suppresses IndexError
2013-09-14 22:17:39 -07:00
Raymond Hettinger
3e6aafe209
Issue #16098 : Update heapq.nsmallest to use the same algorithm as nlargest.
...
This removes the dependency on bisect and it bring the pure Python code
in-sync with the C code.
2013-03-05 02:15:01 -05:00
Raymond Hettinger
e11a47e207
Issue 13274: Make the pure python code for heapq more closely match the C implementation for an undefined corner case.
2011-10-30 14:29:06 -07:00
Éric Araujo
4800d6470c
Minor tweaks to a few comments in heapq
2011-04-15 23:34:31 +02:00
Raymond Hettinger
9b342c6fd4
Issue 3051: make pure python code pass the same tests as the C version.
2011-04-13 11:15:58 -07:00
Raymond Hettinger
b006fcc30c
Make life easier for non-CPython implementations.
2009-03-29 18:51:11 +00:00
Raymond Hettinger
be9b765c07
Speedup and simplify negative counter using count's new step argument.
2009-02-21 08:58:42 +00:00
Benjamin Peterson
fb921e2c00
I believe the intention here was to avoid a global lookup
2009-01-31 21:00:10 +00:00
Benjamin Peterson
b6e112bd95
fix encoding cookie case
2009-01-18 22:47:04 +00:00
Raymond Hettinger
b5bc33cdab
Optimize heapq.nsmallest/nlargest for cases where n==1 or n>=size.
2009-01-12 10:37:32 +00:00
Georg Brandl
fe427895b5
Manually merge r68095,68186,68187,68188,68190 from 2.6 branch.
2009-01-03 22:03:11 +00:00
Raymond Hettinger
6d7702ecd1
Implement heapq in terms of less-than (to match list.sort()).
2008-05-31 03:24:31 +00:00
Raymond Hettinger
83aa6a3b1a
Simplify the nlargest() code using heappushpop().
2008-03-13 19:33:34 +00:00
Raymond Hettinger
53bdf09343
Issue 2274: Add heapq.heappushpop().
2008-03-13 19:03:51 +00:00
Raymond Hettinger
3035d2397f
Docstring nit.
2007-02-28 18:27:41 +00:00
Raymond Hettinger
cbac8ce5b0
Fixup docstrings for merge().
2007-02-19 18:15:04 +00:00
Raymond Hettinger
45eb0f1419
Use C heapreplace() instead of slower _siftup() in pure python.
2007-02-19 06:59:32 +00:00
Raymond Hettinger
54da9819cc
Add tie-breaker count to preserve sort stability.
2007-02-19 05:28:28 +00:00
Raymond Hettinger
00166c5532
Add merge() function to heapq.
2007-02-19 04:08:43 +00:00
Raymond Hettinger
769a40a1d0
Fix stability of heapq's nlargest() and nsmallest().
2007-01-04 17:53:34 +00:00
Raymond Hettinger
4901a1f267
Add key= argument to heapq.nsmallest() and heapq.nlargest().
2004-12-02 08:59:14 +00:00
Raymond Hettinger
e1defa4175
Fix argument order in pure python version of nsmallest() and nlargest().
2004-11-29 05:54:48 +00:00
Raymond Hettinger
8158e84930
Fix erroneous docstring comment.
2004-09-06 07:04:09 +00:00
Raymond Hettinger
28224f897a
Improve the documented advice on how to best use heapq.heapreplace().
2004-06-20 09:07:53 +00:00
Raymond Hettinger
2e3dfaf707
Install C version of heapq.nsmallest().
2004-06-13 05:26:33 +00:00
Raymond Hettinger
b25aa36f83
Improve the memory performance and speed of heapq.nsmallest() by using
...
an alternate algorithm when the number of selected items is small
relative to the full iterable.
2004-06-12 08:33:36 +00:00
Raymond Hettinger
33ecffb65a
SF patch #969791 : Add nlargest() and nsmallest() to heapq.
2004-06-10 05:03:17 +00:00
Raymond Hettinger
c46cb2a1a9
* Restore the pure python version of heapq.py.
...
* Mark the C version as private and only use when available.
2004-04-19 19:06:21 +00:00
Raymond Hettinger
b3af1813eb
Convert heapq.py to a C implementation.
2003-11-08 10:24:38 +00:00
Raymond Hettinger
85c20a41df
Implement and apply PEP 322, reverse iteration
2003-11-06 14:06:48 +00:00
Walter Dörwald
f0dfc7ac5c
Fix a bunch of typos in documentation, docstrings and comments.
...
(From SF patch #810751 )
2003-10-20 14:01:56 +00:00
Fred Drake
f2928eb017
Fix typo in comment.
2002-11-13 14:38:17 +00:00
Raymond Hettinger
a853cc6647
Added __all__.
2002-10-30 06:15:53 +00:00
Tim Peters
5f7617b5f6
Fixed misspelling in comment.
2002-08-11 18:28:09 +00:00
Tim Peters
469cdad822
Whitespace normalization.
2002-08-08 20:19:19 +00:00
Guido van Rossum
3c8dd0c6e7
Simplify heapreplace() -- there's no need for an explicit test for
...
empty heap, since heap[0] raises the appropriate IndexError already.
2002-08-07 18:58:11 +00:00
Tim Peters
6681de2455
_siftup(): __le__ is now the only comparison operator used on array
...
elements.
2002-08-03 19:20:16 +00:00
Tim Peters
0cd53a6c37
Added new heapreplace(heap, item) function, to pop (and return) the
...
currently-smallest value, and add item, in one gulp. See the second
N-Best algorithm in the test suite for a natural use.
2002-08-03 10:10:10 +00:00
Tim Peters
657fe38241
Large code rearrangement to use better algorithms, in the sense of needing
...
substantially fewer array-element compares. This is best practice as of
Kntuh Volume 3 Ed 2, and the code is actually simpler this way (although
the key idea may be counter-intuitive at first glance! breaking out of
a loop early loses when it costs more to try to get out early than getting
out early saves).
Also added a comment block explaining the difference and giving some real
counts; demonstrating that heapify() is more efficient than repeated
heappush(); and emphasizing the obvious point thatlist.sort() is more
efficient if what you really want to do is sort.
2002-08-03 09:56:52 +00:00
Tim Peters
aa7d24319e
Minor fiddling, including a simple class to implement a heap iterator
...
in the test file. I have docs for heapq.heapify ready to check in, but
Jack appears to have left behind a stale lock in the Doc/lib directory.
2002-08-03 02:11:26 +00:00
Guido van Rossum
fbb299226d
Augment credits.
2002-08-02 22:01:37 +00:00
Tim Peters
28c25527c2
Hmm! I thought I checked this in before! Oh well.
...
Added new heapify() function, which transforms an arbitrary list into a
heap in linear time; that's a fundamental tool for using heaps in real
life <wink>.
Added heapyify() test. Added a "less naive" N-best algorithm to the test
suite, and noted that this could actually go much faster (building on
heapify()) if we had max-heaps instead of min-heaps (the iterative method
is appropriate when all the data isn't known in advance, but when it is
known in advance the tradeoffs get murkier).
2002-08-02 21:48:06 +00:00
Guido van Rossum
4b48d6b37c
Add a PEP-263-style encoding turd^H^H^H^Hdeclaration, because there's
...
a c-cedilla in one of the docstrings.
2002-08-02 20:23:56 +00:00
Tim Peters
62abc2f6ce
heappop(): Added comments; simplified and sped the code.
2002-08-02 20:09:14 +00:00
Tim Peters
a0b3a00bc5
heappop(): Use "while True" instead of "while 1".
2002-08-02 19:45:37 +00:00
Tim Peters
d9ea39db84
Don't use true division where int division was intended. For that matter,
...
don't use division at all.
2002-08-02 19:16:44 +00:00
Guido van Rossum
37c3b2788b
Add Kevin O'Connor, author of the heapq code.
2002-08-02 16:50:58 +00:00
Guido van Rossum
0a82438859
Adding the heap queue algorithm, per discussion in python-dev last
...
week.
2002-08-02 16:44:32 +00:00