2021-08-12 13:59:29 +10:00
|
|
|
:mod:`heapq` -- heap queue algorithm
|
|
|
|
====================================
|
2014-10-31 01:37:19 +00:00
|
|
|
|
2018-02-20 17:34:59 -08:00
|
|
|
.. include:: ../templates/unsupported_in_circuitpython.inc
|
|
|
|
|
2021-08-12 13:59:29 +10:00
|
|
|
.. module:: heapq
|
2014-10-31 01:37:19 +00:00
|
|
|
:synopsis: heap queue algorithm
|
|
|
|
|
2018-02-20 17:34:59 -08:00
|
|
|
|see_cpython_module| :mod:`cpython:heapq`.
|
2017-07-02 15:37:31 +03:00
|
|
|
|
2021-05-16 20:11:44 -07: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-16 20:11:44 -07: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-16 20:11:44 -07:00
|
|
|
Pop the first item from the ``heap``, and return it. Raise ``IndexError`` if
|
|
|
|
``heap`` is empty.
|
2021-06-18 10:54:19 -05:00
|
|
|
|
2021-05-16 20:11:44 -07: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.
|