From 3badabd49a84126cb3eddc3c4ab031217a5ba568 Mon Sep 17 00:00:00 2001 From: Chris Cooper Date: Thu, 28 Sep 2023 17:29:37 -0700 Subject: [PATCH] Add maxheap version of heappush. --- Lib/heapq.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Lib/heapq.py b/Lib/heapq.py index 2fd9d1ff4bf827..dbb8947c16a824 100644 --- a/Lib/heapq.py +++ b/Lib/heapq.py @@ -188,6 +188,11 @@ def _heappop_max(heap): return returnitem return lastelt +def _heappush_max(heap, item): + """Maxheap version of a heappush.""" + heap.append(item) + _siftdown_max(heap, 0, len(heap)-1) + def _heapreplace_max(heap, item): """Maxheap version of a heappop followed by a heappush.""" returnitem = heap[0] # raises appropriate IndexError if heap is empty