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