summaryrefslogtreecommitdiffstats
path: root/Lib/heapq.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2014-06-14 23:43:35 (GMT)
committerRaymond Hettinger <python@rcn.com>2014-06-14 23:43:35 (GMT)
commit48f68d00b8e017050489635c04c82153a345a336 (patch)
tree3aacfe3a6c6998200bf003619319f4cc3616b8a6 /Lib/heapq.py
parent892051af95729098ce4f5fc7f17ca7049c100b14 (diff)
downloadcpython-48f68d00b8e017050489635c04c82153a345a336.zip
cpython-48f68d00b8e017050489635c04c82153a345a336.tar.gz
cpython-48f68d00b8e017050489635c04c82153a345a336.tar.bz2
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.
Diffstat (limited to 'Lib/heapq.py')
-rw-r--r--Lib/heapq.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/Lib/heapq.py b/Lib/heapq.py
index b20f04d..8fb3d09 100644
--- a/Lib/heapq.py
+++ b/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__":