(root)/
Python-3.12.0/
Modules/
clinic/
_heapqmodule.c.h
       1  /*[clinic input]
       2  preserve
       3  [clinic start generated code]*/
       4  
       5  #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
       6  #  include "pycore_gc.h"            // PyGC_Head
       7  #  include "pycore_runtime.h"       // _Py_ID()
       8  #endif
       9  
      10  
      11  PyDoc_STRVAR(_heapq_heappush__doc__,
      12  "heappush($module, heap, item, /)\n"
      13  "--\n"
      14  "\n"
      15  "Push item onto heap, maintaining the heap invariant.");
      16  
      17  #define _HEAPQ_HEAPPUSH_METHODDEF    \
      18      {"heappush", _PyCFunction_CAST(_heapq_heappush), METH_FASTCALL, _heapq_heappush__doc__},
      19  
      20  static PyObject *
      21  _heapq_heappush_impl(PyObject *module, PyObject *heap, PyObject *item);
      22  
      23  static PyObject *
      24  _heapq_heappush(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
      25  {
      26      PyObject *return_value = NULL;
      27      PyObject *heap;
      28      PyObject *item;
      29  
      30      if (!_PyArg_CheckPositional("heappush", nargs, 2, 2)) {
      31          goto exit;
      32      }
      33      if (!PyList_Check(args[0])) {
      34          _PyArg_BadArgument("heappush", "argument 1", "list", args[0]);
      35          goto exit;
      36      }
      37      heap = args[0];
      38      item = args[1];
      39      return_value = _heapq_heappush_impl(module, heap, item);
      40  
      41  exit:
      42      return return_value;
      43  }
      44  
      45  PyDoc_STRVAR(_heapq_heappop__doc__,
      46  "heappop($module, heap, /)\n"
      47  "--\n"
      48  "\n"
      49  "Pop the smallest item off the heap, maintaining the heap invariant.");
      50  
      51  #define _HEAPQ_HEAPPOP_METHODDEF    \
      52      {"heappop", (PyCFunction)_heapq_heappop, METH_O, _heapq_heappop__doc__},
      53  
      54  static PyObject *
      55  _heapq_heappop_impl(PyObject *module, PyObject *heap);
      56  
      57  static PyObject *
      58  _heapq_heappop(PyObject *module, PyObject *arg)
      59  {
      60      PyObject *return_value = NULL;
      61      PyObject *heap;
      62  
      63      if (!PyList_Check(arg)) {
      64          _PyArg_BadArgument("heappop", "argument", "list", arg);
      65          goto exit;
      66      }
      67      heap = arg;
      68      return_value = _heapq_heappop_impl(module, heap);
      69  
      70  exit:
      71      return return_value;
      72  }
      73  
      74  PyDoc_STRVAR(_heapq_heapreplace__doc__,
      75  "heapreplace($module, heap, item, /)\n"
      76  "--\n"
      77  "\n"
      78  "Pop and return the current smallest value, and add the new item.\n"
      79  "\n"
      80  "This is more efficient than heappop() followed by heappush(), and can be\n"
      81  "more appropriate when using a fixed-size heap.  Note that the value\n"
      82  "returned may be larger than item!  That constrains reasonable uses of\n"
      83  "this routine unless written as part of a conditional replacement:\n"
      84  "\n"
      85  "    if item > heap[0]:\n"
      86  "        item = heapreplace(heap, item)");
      87  
      88  #define _HEAPQ_HEAPREPLACE_METHODDEF    \
      89      {"heapreplace", _PyCFunction_CAST(_heapq_heapreplace), METH_FASTCALL, _heapq_heapreplace__doc__},
      90  
      91  static PyObject *
      92  _heapq_heapreplace_impl(PyObject *module, PyObject *heap, PyObject *item);
      93  
      94  static PyObject *
      95  _heapq_heapreplace(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
      96  {
      97      PyObject *return_value = NULL;
      98      PyObject *heap;
      99      PyObject *item;
     100  
     101      if (!_PyArg_CheckPositional("heapreplace", nargs, 2, 2)) {
     102          goto exit;
     103      }
     104      if (!PyList_Check(args[0])) {
     105          _PyArg_BadArgument("heapreplace", "argument 1", "list", args[0]);
     106          goto exit;
     107      }
     108      heap = args[0];
     109      item = args[1];
     110      return_value = _heapq_heapreplace_impl(module, heap, item);
     111  
     112  exit:
     113      return return_value;
     114  }
     115  
     116  PyDoc_STRVAR(_heapq_heappushpop__doc__,
     117  "heappushpop($module, heap, item, /)\n"
     118  "--\n"
     119  "\n"
     120  "Push item on the heap, then pop and return the smallest item from the heap.\n"
     121  "\n"
     122  "The combined action runs more efficiently than heappush() followed by\n"
     123  "a separate call to heappop().");
     124  
     125  #define _HEAPQ_HEAPPUSHPOP_METHODDEF    \
     126      {"heappushpop", _PyCFunction_CAST(_heapq_heappushpop), METH_FASTCALL, _heapq_heappushpop__doc__},
     127  
     128  static PyObject *
     129  _heapq_heappushpop_impl(PyObject *module, PyObject *heap, PyObject *item);
     130  
     131  static PyObject *
     132  _heapq_heappushpop(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     133  {
     134      PyObject *return_value = NULL;
     135      PyObject *heap;
     136      PyObject *item;
     137  
     138      if (!_PyArg_CheckPositional("heappushpop", nargs, 2, 2)) {
     139          goto exit;
     140      }
     141      if (!PyList_Check(args[0])) {
     142          _PyArg_BadArgument("heappushpop", "argument 1", "list", args[0]);
     143          goto exit;
     144      }
     145      heap = args[0];
     146      item = args[1];
     147      return_value = _heapq_heappushpop_impl(module, heap, item);
     148  
     149  exit:
     150      return return_value;
     151  }
     152  
     153  PyDoc_STRVAR(_heapq_heapify__doc__,
     154  "heapify($module, heap, /)\n"
     155  "--\n"
     156  "\n"
     157  "Transform list into a heap, in-place, in O(len(heap)) time.");
     158  
     159  #define _HEAPQ_HEAPIFY_METHODDEF    \
     160      {"heapify", (PyCFunction)_heapq_heapify, METH_O, _heapq_heapify__doc__},
     161  
     162  static PyObject *
     163  _heapq_heapify_impl(PyObject *module, PyObject *heap);
     164  
     165  static PyObject *
     166  _heapq_heapify(PyObject *module, PyObject *arg)
     167  {
     168      PyObject *return_value = NULL;
     169      PyObject *heap;
     170  
     171      if (!PyList_Check(arg)) {
     172          _PyArg_BadArgument("heapify", "argument", "list", arg);
     173          goto exit;
     174      }
     175      heap = arg;
     176      return_value = _heapq_heapify_impl(module, heap);
     177  
     178  exit:
     179      return return_value;
     180  }
     181  
     182  PyDoc_STRVAR(_heapq__heappop_max__doc__,
     183  "_heappop_max($module, heap, /)\n"
     184  "--\n"
     185  "\n"
     186  "Maxheap variant of heappop.");
     187  
     188  #define _HEAPQ__HEAPPOP_MAX_METHODDEF    \
     189      {"_heappop_max", (PyCFunction)_heapq__heappop_max, METH_O, _heapq__heappop_max__doc__},
     190  
     191  static PyObject *
     192  _heapq__heappop_max_impl(PyObject *module, PyObject *heap);
     193  
     194  static PyObject *
     195  _heapq__heappop_max(PyObject *module, PyObject *arg)
     196  {
     197      PyObject *return_value = NULL;
     198      PyObject *heap;
     199  
     200      if (!PyList_Check(arg)) {
     201          _PyArg_BadArgument("_heappop_max", "argument", "list", arg);
     202          goto exit;
     203      }
     204      heap = arg;
     205      return_value = _heapq__heappop_max_impl(module, heap);
     206  
     207  exit:
     208      return return_value;
     209  }
     210  
     211  PyDoc_STRVAR(_heapq__heapreplace_max__doc__,
     212  "_heapreplace_max($module, heap, item, /)\n"
     213  "--\n"
     214  "\n"
     215  "Maxheap variant of heapreplace.");
     216  
     217  #define _HEAPQ__HEAPREPLACE_MAX_METHODDEF    \
     218      {"_heapreplace_max", _PyCFunction_CAST(_heapq__heapreplace_max), METH_FASTCALL, _heapq__heapreplace_max__doc__},
     219  
     220  static PyObject *
     221  _heapq__heapreplace_max_impl(PyObject *module, PyObject *heap,
     222                               PyObject *item);
     223  
     224  static PyObject *
     225  _heapq__heapreplace_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     226  {
     227      PyObject *return_value = NULL;
     228      PyObject *heap;
     229      PyObject *item;
     230  
     231      if (!_PyArg_CheckPositional("_heapreplace_max", nargs, 2, 2)) {
     232          goto exit;
     233      }
     234      if (!PyList_Check(args[0])) {
     235          _PyArg_BadArgument("_heapreplace_max", "argument 1", "list", args[0]);
     236          goto exit;
     237      }
     238      heap = args[0];
     239      item = args[1];
     240      return_value = _heapq__heapreplace_max_impl(module, heap, item);
     241  
     242  exit:
     243      return return_value;
     244  }
     245  
     246  PyDoc_STRVAR(_heapq__heapify_max__doc__,
     247  "_heapify_max($module, heap, /)\n"
     248  "--\n"
     249  "\n"
     250  "Maxheap variant of heapify.");
     251  
     252  #define _HEAPQ__HEAPIFY_MAX_METHODDEF    \
     253      {"_heapify_max", (PyCFunction)_heapq__heapify_max, METH_O, _heapq__heapify_max__doc__},
     254  
     255  static PyObject *
     256  _heapq__heapify_max_impl(PyObject *module, PyObject *heap);
     257  
     258  static PyObject *
     259  _heapq__heapify_max(PyObject *module, PyObject *arg)
     260  {
     261      PyObject *return_value = NULL;
     262      PyObject *heap;
     263  
     264      if (!PyList_Check(arg)) {
     265          _PyArg_BadArgument("_heapify_max", "argument", "list", arg);
     266          goto exit;
     267      }
     268      heap = arg;
     269      return_value = _heapq__heapify_max_impl(module, heap);
     270  
     271  exit:
     272      return return_value;
     273  }
     274  /*[clinic end generated code: output=29e99a48c57f82bb input=a9049054013a1b77]*/