@@ -482,7 +482,7 @@ siftup_max(PyListObject *heap, Py_ssize_t pos)
482482
483483
484484/*[clinic input]
485- _heapq._heappop_max
485+ _heapq.heappop_max
486486
487487 heap: object(subclass_of='&PyList_Type')
488488 /
@@ -491,14 +491,14 @@ Maxheap variant of heappop.
491491[clinic start generated code]*/
492492
493493static PyObject *
494- _heapq__heappop_max_impl (PyObject * module , PyObject * heap )
495- /*[clinic end generated code: output=9e77aadd4e6a8760 input=362c06e1c7484793 ]*/
494+ _heapq_heappop_max_impl (PyObject * module , PyObject * heap )
495+ /*[clinic end generated code: output=2f051195ab404b77 input=e62b14016a5a26de ]*/
496496{
497497 return heappop_internal (heap , siftup_max );
498498}
499499
500500/*[clinic input]
501- _heapq._heapreplace_max
501+ _heapq.heapreplace_max
502502
503503 heap: object(subclass_of='&PyList_Type')
504504 item: object
@@ -508,15 +508,14 @@ Maxheap variant of heapreplace.
508508[clinic start generated code]*/
509509
510510static PyObject *
511- _heapq__heapreplace_max_impl (PyObject * module , PyObject * heap ,
512- PyObject * item )
513- /*[clinic end generated code: output=8ad7545e4a5e8adb input=f2dd27cbadb948d7]*/
511+ _heapq_heapreplace_max_impl (PyObject * module , PyObject * heap , PyObject * item )
512+ /*[clinic end generated code: output=8770778b5a9cbe9b input=21a3d28d757c881c]*/
514513{
515514 return heapreplace_internal (heap , item , siftup_max );
516515}
517516
518517/*[clinic input]
519- _heapq._heapify_max
518+ _heapq.heapify_max
520519
521520 heap: object(subclass_of='&PyList_Type')
522521 /
@@ -525,21 +524,63 @@ Maxheap variant of heapify.
525524[clinic start generated code]*/
526525
527526static PyObject *
528- _heapq__heapify_max_impl (PyObject * module , PyObject * heap )
529- /*[clinic end generated code: output=2cb028beb4a8b65e input=c1f765ee69f124b8 ]*/
527+ _heapq_heapify_max_impl (PyObject * module , PyObject * heap )
528+ /*[clinic end generated code: output=8401af3856529807 input=edda4255728c431e ]*/
530529{
531530 return heapify_internal (heap , siftup_max );
532531}
533532
533+ /*[clinic input]
534+ _heapq.heappushpop_max
535+
536+ heap: object(subclass_of='&PyList_Type')
537+ item: object
538+ /
539+
540+ Maxheap variant of heappushpop.
541+
542+ The combined action runs more efficiently than heappush_max() followed by
543+ a separate call to heappop_max().
544+ [clinic start generated code]*/
545+
546+ static PyObject *
547+ _heapq_heappushpop_max_impl (PyObject * module , PyObject * heap , PyObject * item )
548+ /*[clinic end generated code: output=ff0019f0941aca0d input=525a843013cbd6c0]*/
549+ {
550+ PyObject * returnitem ;
551+ int cmp ;
552+ if (PyList_GET_SIZE (heap ) == 0 ) {
553+ return Py_NewRef (item );
554+ }
555+ PyObject * top = PyList_GET_ITEM (heap , 0 );
556+ Py_INCREF (top );
557+ cmp = PyObject_RichCompareBool (top , item , Py_LT );
558+ Py_DECREF (top );
559+ if (cmp < 0 )
560+ return NULL ;
561+ if (cmp == 0 ) {
562+ return Py_NewRef (item );
563+ }
564+ returnitem = PyList_GET_ITEM (heap , 0 );
565+ PyList_SET_ITEM (heap , 0 , Py_NewRef (item ));
566+
567+ if (siftup_max ((PyListObject * )heap , 0 )) {
568+ Py_DECREF (returnitem );
569+ return NULL ;
570+ }
571+ return Py_NewRef (returnitem );
572+ }
573+
534574static PyMethodDef heapq_methods [] = {
535575 _HEAPQ_HEAPPUSH_METHODDEF
536576 _HEAPQ_HEAPPUSHPOP_METHODDEF
537577 _HEAPQ_HEAPPOP_METHODDEF
538578 _HEAPQ_HEAPREPLACE_METHODDEF
539579 _HEAPQ_HEAPIFY_METHODDEF
540- _HEAPQ__HEAPPOP_MAX_METHODDEF
541- _HEAPQ__HEAPIFY_MAX_METHODDEF
542- _HEAPQ__HEAPREPLACE_MAX_METHODDEF
580+ _HEAPQ_HEAPPOP_MAX_METHODDEF
581+ _HEAPQ_HEAPIFY_MAX_METHODDEF
582+ _HEAPQ_HEAPREPLACE_MAX_METHODDEF
583+ _HEAPQ_HEAPPUSHPOP_MAX_METHODDEF
543584 {NULL , NULL } /* sentinel */
544585};
545586
0 commit comments