mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Factor common code into internal functions.
Clean-up names of static functions. Use Py_RETURN_NONE macro. Expose private functions needed to support merge(). Move C imports to the bottom of the Python file.
This commit is contained in:
parent
892051af95
commit
48f68d00b8
3 changed files with 76 additions and 54 deletions
28
Lib/heapq.py
28
Lib/heapq.py
|
@ -311,16 +311,6 @@ def _siftup_max(heap, pos):
|
|||
heap[pos] = newitem
|
||||
_siftdown_max(heap, startpos, pos)
|
||||
|
||||
# If available, use C implementation
|
||||
try:
|
||||
from _heapq import *
|
||||
except ImportError:
|
||||
pass
|
||||
try:
|
||||
from _heapq import _heapreplace_max
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
def merge(*iterables, key=None, reverse=False):
|
||||
'''Merge multiple sorted inputs into a single sorted output.
|
||||
|
||||
|
@ -592,6 +582,24 @@ def nlargest(n, iterable, key=None):
|
|||
result.sort(reverse=True)
|
||||
return [r[2] for r in result]
|
||||
|
||||
# If available, use C implementation
|
||||
try:
|
||||
from _heapq import *
|
||||
except ImportError:
|
||||
pass
|
||||
try:
|
||||
from _heapq import _heapreplace_max
|
||||
except ImportError:
|
||||
pass
|
||||
try:
|
||||
from _heapq import _heapify_max
|
||||
except ImportError:
|
||||
pass
|
||||
try:
|
||||
from _heapq import _heappop_max
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue