MCPcopy Index your code
hub / github.com/RustPython/RustPython / heapify

Function heapify

Lib/heapq.py:171–180  ·  view source on GitHub ↗

Transform list into a heap, in-place, in O(len(x)) time.

(x)

Source from the content-addressed store, hash-verified

169 return item
170
171def heapify(x):
172 """Transform list into a heap, in-place, in O(len(x)) time."""
173 n = len(x)
174 # Transform bottom-up. The largest index there's any point to looking at
175 # is the largest with a child index in-range, so must have 2*i + 1 < n,
176 # or i < (n-1)/2. If n is even = 2*j, this is (2*j-1)/2 = j-1/2 so
177 # j-1 is the largest, which is n//2 - 1. If n is odd = 2*j+1, this is
178 # (2*j+1-1)/2 = j so j-1 is the largest, and that's again n//2-1.
179 for i in reversed(range(n//2)):
180 _siftup(x, i)
181
182def heappop_max(heap):
183 """Maxheap version of a heappop."""

Callers 1

nlargestFunction · 0.85

Calls 3

lenFunction · 0.85
reversedFunction · 0.85
_siftupFunction · 0.85

Tested by

no test coverage detected