Lines Matching refs:heap
140 def heappush(heap, item): argument
142 heap.append(item)
143 _siftdown(heap, 0, len(heap)-1)
145 def heappop(heap): argument
147 lastelt = heap.pop() # raises appropriate IndexError if heap is empty
148 if heap:
149 returnitem = heap[0]
150 heap[0] = lastelt
151 _siftup(heap, 0)
156 def heapreplace(heap, item): argument
167 returnitem = heap[0] # raises appropriate IndexError if heap is empty
168 heap[0] = item
169 _siftup(heap, 0)
172 def heappushpop(heap, item): argument
174 if heap and cmp_lt(heap[0], item):
175 item, heap[0] = heap[0], item
176 _siftup(heap, 0)
190 def _heappushpop_max(heap, item): argument
192 if heap and cmp_lt(item, heap[0]):
193 item, heap[0] = heap[0], item
194 _siftup_max(heap, 0)
242 def _siftdown(heap, startpos, pos): argument
243 newitem = heap[pos]
248 parent = heap[parentpos]
250 heap[pos] = parent
254 heap[pos] = newitem
295 def _siftup(heap, pos): argument
296 endpos = len(heap)
298 newitem = heap[pos]
304 if rightpos < endpos and not cmp_lt(heap[childpos], heap[rightpos]):
307 heap[pos] = heap[childpos]
312 heap[pos] = newitem
313 _siftdown(heap, startpos, pos)
315 def _siftdown_max(heap, startpos, pos): argument
317 newitem = heap[pos]
322 parent = heap[parentpos]
324 heap[pos] = parent
328 heap[pos] = newitem
330 def _siftup_max(heap, pos): argument
332 endpos = len(heap)
334 newitem = heap[pos]
340 if rightpos < endpos and not cmp_lt(heap[rightpos], heap[childpos]):
343 heap[pos] = heap[childpos]
348 heap[pos] = newitem
349 _siftdown_max(heap, startpos, pos)
475 heap = [] variable
478 heappush(heap, item)
480 while heap:
481 sort.append(heappop(heap))