pocketpy/docs/modules/heapq.md
blueloveTH d513a3b459 ...
2023-04-23 12:42:42 +08:00

24 lines
838 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
icon: package
label: heapq
---
### `heapq.heappush(heap, item)`
Push the value `item` onto the heap, maintaining the heap invariant.
### `heapq.heappop(heap)`
Pop and return the smallest item from the heap, maintaining the heap invariant. If the heap is empty, IndexError is raised. To access the smallest item without popping it, use `heap[0]`.
### `heapq.heapify(x)`
Transform list `x` into a heap, in-place, in linear time.
### `heapq.heappushpop(heap, item)`
Push `item` on the heap, then pop and return the smallest item from the heap. The combined action runs more efficiently than `heappush()` followed by a separate `heappop()`.
### `heapq.heapreplace(heap, item)`
Pop and return the smallest item from the heap, and also push the new item. The heap size doesnt change. If the heap is empty, IndexError is raised.