Debian Codegraph @

Modules/clinic/_heapqmodule.c.h

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