2021-08-12 04:59:29 +01:00
|
|
|
:mod:`heapq` -- heap queue algorithm
|
|
|
|
====================================
|
2014-10-31 01:37:19 +00:00
|
|
|
|
2021-08-12 04:59:29 +01:00
|
|
|
.. module:: heapq
|
2014-10-31 01:37:19 +00:00
|
|
|
:synopsis: heap queue algorithm
|
|
|
|
|
2017-07-02 13:37:31 +01:00
|
|
|
|see_cpython_module| :mod:`python:heapq`.
|
|
|
|
|
2021-05-17 04:11:44 +01:00
|
|
|
This module implements the
|
|
|
|
`min heap queue algorithm <https://en.wikipedia.org/wiki/Heap_%28data_structure%29>`_.
|
2014-10-31 01:37:19 +00:00
|
|
|
|
2021-05-17 04:11:44 +01:00
|
|
|
A heap queue is essentially a list that has its elements stored in such a way
|
|
|
|
that the first item of the list is always the smallest.
|
2014-10-31 01:37:19 +00:00
|
|
|
|
|
|
|
Functions
|
|
|
|
---------
|
|
|
|
|
|
|
|
.. function:: heappush(heap, item)
|
|
|
|
|
|
|
|
Push the ``item`` onto the ``heap``.
|
|
|
|
|
|
|
|
.. function:: heappop(heap)
|
|
|
|
|
2021-05-17 04:11:44 +01:00
|
|
|
Pop the first item from the ``heap``, and return it. Raise ``IndexError`` if
|
|
|
|
``heap`` is empty.
|
2021-12-15 00:49:22 +00:00
|
|
|
|
2021-05-17 04:11:44 +01:00
|
|
|
The returned item will be the smallest item in the ``heap``.
|
2014-10-31 01:37:19 +00:00
|
|
|
|
|
|
|
.. function:: heapify(x)
|
|
|
|
|
|
|
|
Convert the list ``x`` into a heap. This is an in-place operation.
|