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

Function _siftup

Lib/heapq.py:274–292  ·  view source on GitHub ↗
(heap, pos)

Source from the content-addressed store, hash-verified

272# for sorting.
273
274def _siftup(heap, pos):
275 endpos = len(heap)
276 startpos = pos
277 newitem = heap[pos]
278 # Bubble up the smaller child until hitting a leaf.
279 childpos = 2*pos + 1 # leftmost child position
280 while childpos < endpos:
281 # Set childpos to index of smaller child.
282 rightpos = childpos + 1
283 if rightpos < endpos and not heap[childpos] < heap[rightpos]:
284 childpos = rightpos
285 # Move the smaller child up.
286 heap[pos] = heap[childpos]
287 pos = childpos
288 childpos = 2*pos + 1
289 # The leaf at pos is empty now. Put newitem there, and bubble it up
290 # to its final resting place (by sifting its parents down).
291 heap[pos] = newitem
292 _siftdown(heap, startpos, pos)
293
294def _siftdown_max(heap, startpos, pos):
295 'Maxheap variant of _siftdown'

Callers 4

heappopFunction · 0.85
heapreplaceFunction · 0.85
heappushpopFunction · 0.85
heapifyFunction · 0.85

Calls 2

lenFunction · 0.85
_siftdownFunction · 0.85

Tested by

no test coverage detected