(root)/
Python-3.11.7/
Modules/
clinic/
_bisectmodule.c.h
       1  /*[clinic input]
       2  preserve
       3  [clinic start generated code]*/
       4  
       5  PyDoc_STRVAR(_bisect_bisect_right__doc__,
       6  "bisect_right($module, /, a, x, lo=0, hi=None, *, key=None)\n"
       7  "--\n"
       8  "\n"
       9  "Return the index where to insert item x in list a, assuming a is sorted.\n"
      10  "\n"
      11  "The return value i is such that all e in a[:i] have e <= x, and all e in\n"
      12  "a[i:] have e > x.  So if x already appears in the list, a.insert(i, x) will\n"
      13  "insert just after the rightmost x already there.\n"
      14  "\n"
      15  "Optional args lo (default 0) and hi (default len(a)) bound the\n"
      16  "slice of a to be searched.");
      17  
      18  #define _BISECT_BISECT_RIGHT_METHODDEF    \
      19      {"bisect_right", _PyCFunction_CAST(_bisect_bisect_right), METH_FASTCALL|METH_KEYWORDS, _bisect_bisect_right__doc__},
      20  
      21  static Py_ssize_t
      22  _bisect_bisect_right_impl(PyObject *module, PyObject *a, PyObject *x,
      23                            Py_ssize_t lo, Py_ssize_t hi, PyObject *key);
      24  
      25  static PyObject *
      26  _bisect_bisect_right(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
      27  {
      28      PyObject *return_value = NULL;
      29      static const char * const _keywords[] = {"a", "x", "lo", "hi", "key", NULL};
      30      static _PyArg_Parser _parser = {NULL, _keywords, "bisect_right", 0};
      31      PyObject *argsbuf[5];
      32      Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
      33      PyObject *a;
      34      PyObject *x;
      35      Py_ssize_t lo = 0;
      36      Py_ssize_t hi = -1;
      37      PyObject *key = Py_None;
      38      Py_ssize_t _return_value;
      39  
      40      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 4, 0, argsbuf);
      41      if (!args) {
      42          goto exit;
      43      }
      44      a = args[0];
      45      x = args[1];
      46      if (!noptargs) {
      47          goto skip_optional_pos;
      48      }
      49      if (args[2]) {
      50          {
      51              Py_ssize_t ival = -1;
      52              PyObject *iobj = _PyNumber_Index(args[2]);
      53              if (iobj != NULL) {
      54                  ival = PyLong_AsSsize_t(iobj);
      55                  Py_DECREF(iobj);
      56              }
      57              if (ival == -1 && PyErr_Occurred()) {
      58                  goto exit;
      59              }
      60              lo = ival;
      61          }
      62          if (!--noptargs) {
      63              goto skip_optional_pos;
      64          }
      65      }
      66      if (args[3]) {
      67          if (!_Py_convert_optional_to_ssize_t(args[3], &hi)) {
      68              goto exit;
      69          }
      70          if (!--noptargs) {
      71              goto skip_optional_pos;
      72          }
      73      }
      74  skip_optional_pos:
      75      if (!noptargs) {
      76          goto skip_optional_kwonly;
      77      }
      78      key = args[4];
      79  skip_optional_kwonly:
      80      _return_value = _bisect_bisect_right_impl(module, a, x, lo, hi, key);
      81      if ((_return_value == -1) && PyErr_Occurred()) {
      82          goto exit;
      83      }
      84      return_value = PyLong_FromSsize_t(_return_value);
      85  
      86  exit:
      87      return return_value;
      88  }
      89  
      90  PyDoc_STRVAR(_bisect_insort_right__doc__,
      91  "insort_right($module, /, a, x, lo=0, hi=None, *, key=None)\n"
      92  "--\n"
      93  "\n"
      94  "Insert item x in list a, and keep it sorted assuming a is sorted.\n"
      95  "\n"
      96  "If x is already in a, insert it to the right of the rightmost x.\n"
      97  "\n"
      98  "Optional args lo (default 0) and hi (default len(a)) bound the\n"
      99  "slice of a to be searched.");
     100  
     101  #define _BISECT_INSORT_RIGHT_METHODDEF    \
     102      {"insort_right", _PyCFunction_CAST(_bisect_insort_right), METH_FASTCALL|METH_KEYWORDS, _bisect_insort_right__doc__},
     103  
     104  static PyObject *
     105  _bisect_insort_right_impl(PyObject *module, PyObject *a, PyObject *x,
     106                            Py_ssize_t lo, Py_ssize_t hi, PyObject *key);
     107  
     108  static PyObject *
     109  _bisect_insort_right(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     110  {
     111      PyObject *return_value = NULL;
     112      static const char * const _keywords[] = {"a", "x", "lo", "hi", "key", NULL};
     113      static _PyArg_Parser _parser = {NULL, _keywords, "insort_right", 0};
     114      PyObject *argsbuf[5];
     115      Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
     116      PyObject *a;
     117      PyObject *x;
     118      Py_ssize_t lo = 0;
     119      Py_ssize_t hi = -1;
     120      PyObject *key = Py_None;
     121  
     122      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 4, 0, argsbuf);
     123      if (!args) {
     124          goto exit;
     125      }
     126      a = args[0];
     127      x = args[1];
     128      if (!noptargs) {
     129          goto skip_optional_pos;
     130      }
     131      if (args[2]) {
     132          {
     133              Py_ssize_t ival = -1;
     134              PyObject *iobj = _PyNumber_Index(args[2]);
     135              if (iobj != NULL) {
     136                  ival = PyLong_AsSsize_t(iobj);
     137                  Py_DECREF(iobj);
     138              }
     139              if (ival == -1 && PyErr_Occurred()) {
     140                  goto exit;
     141              }
     142              lo = ival;
     143          }
     144          if (!--noptargs) {
     145              goto skip_optional_pos;
     146          }
     147      }
     148      if (args[3]) {
     149          if (!_Py_convert_optional_to_ssize_t(args[3], &hi)) {
     150              goto exit;
     151          }
     152          if (!--noptargs) {
     153              goto skip_optional_pos;
     154          }
     155      }
     156  skip_optional_pos:
     157      if (!noptargs) {
     158          goto skip_optional_kwonly;
     159      }
     160      key = args[4];
     161  skip_optional_kwonly:
     162      return_value = _bisect_insort_right_impl(module, a, x, lo, hi, key);
     163  
     164  exit:
     165      return return_value;
     166  }
     167  
     168  PyDoc_STRVAR(_bisect_bisect_left__doc__,
     169  "bisect_left($module, /, a, x, lo=0, hi=None, *, key=None)\n"
     170  "--\n"
     171  "\n"
     172  "Return the index where to insert item x in list a, assuming a is sorted.\n"
     173  "\n"
     174  "The return value i is such that all e in a[:i] have e < x, and all e in\n"
     175  "a[i:] have e >= x.  So if x already appears in the list, a.insert(i, x) will\n"
     176  "insert just before the leftmost x already there.\n"
     177  "\n"
     178  "Optional args lo (default 0) and hi (default len(a)) bound the\n"
     179  "slice of a to be searched.");
     180  
     181  #define _BISECT_BISECT_LEFT_METHODDEF    \
     182      {"bisect_left", _PyCFunction_CAST(_bisect_bisect_left), METH_FASTCALL|METH_KEYWORDS, _bisect_bisect_left__doc__},
     183  
     184  static Py_ssize_t
     185  _bisect_bisect_left_impl(PyObject *module, PyObject *a, PyObject *x,
     186                           Py_ssize_t lo, Py_ssize_t hi, PyObject *key);
     187  
     188  static PyObject *
     189  _bisect_bisect_left(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     190  {
     191      PyObject *return_value = NULL;
     192      static const char * const _keywords[] = {"a", "x", "lo", "hi", "key", NULL};
     193      static _PyArg_Parser _parser = {NULL, _keywords, "bisect_left", 0};
     194      PyObject *argsbuf[5];
     195      Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
     196      PyObject *a;
     197      PyObject *x;
     198      Py_ssize_t lo = 0;
     199      Py_ssize_t hi = -1;
     200      PyObject *key = Py_None;
     201      Py_ssize_t _return_value;
     202  
     203      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 4, 0, argsbuf);
     204      if (!args) {
     205          goto exit;
     206      }
     207      a = args[0];
     208      x = args[1];
     209      if (!noptargs) {
     210          goto skip_optional_pos;
     211      }
     212      if (args[2]) {
     213          {
     214              Py_ssize_t ival = -1;
     215              PyObject *iobj = _PyNumber_Index(args[2]);
     216              if (iobj != NULL) {
     217                  ival = PyLong_AsSsize_t(iobj);
     218                  Py_DECREF(iobj);
     219              }
     220              if (ival == -1 && PyErr_Occurred()) {
     221                  goto exit;
     222              }
     223              lo = ival;
     224          }
     225          if (!--noptargs) {
     226              goto skip_optional_pos;
     227          }
     228      }
     229      if (args[3]) {
     230          if (!_Py_convert_optional_to_ssize_t(args[3], &hi)) {
     231              goto exit;
     232          }
     233          if (!--noptargs) {
     234              goto skip_optional_pos;
     235          }
     236      }
     237  skip_optional_pos:
     238      if (!noptargs) {
     239          goto skip_optional_kwonly;
     240      }
     241      key = args[4];
     242  skip_optional_kwonly:
     243      _return_value = _bisect_bisect_left_impl(module, a, x, lo, hi, key);
     244      if ((_return_value == -1) && PyErr_Occurred()) {
     245          goto exit;
     246      }
     247      return_value = PyLong_FromSsize_t(_return_value);
     248  
     249  exit:
     250      return return_value;
     251  }
     252  
     253  PyDoc_STRVAR(_bisect_insort_left__doc__,
     254  "insort_left($module, /, a, x, lo=0, hi=None, *, key=None)\n"
     255  "--\n"
     256  "\n"
     257  "Insert item x in list a, and keep it sorted assuming a is sorted.\n"
     258  "\n"
     259  "If x is already in a, insert it to the left of the leftmost x.\n"
     260  "\n"
     261  "Optional args lo (default 0) and hi (default len(a)) bound the\n"
     262  "slice of a to be searched.");
     263  
     264  #define _BISECT_INSORT_LEFT_METHODDEF    \
     265      {"insort_left", _PyCFunction_CAST(_bisect_insort_left), METH_FASTCALL|METH_KEYWORDS, _bisect_insort_left__doc__},
     266  
     267  static PyObject *
     268  _bisect_insort_left_impl(PyObject *module, PyObject *a, PyObject *x,
     269                           Py_ssize_t lo, Py_ssize_t hi, PyObject *key);
     270  
     271  static PyObject *
     272  _bisect_insort_left(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     273  {
     274      PyObject *return_value = NULL;
     275      static const char * const _keywords[] = {"a", "x", "lo", "hi", "key", NULL};
     276      static _PyArg_Parser _parser = {NULL, _keywords, "insort_left", 0};
     277      PyObject *argsbuf[5];
     278      Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
     279      PyObject *a;
     280      PyObject *x;
     281      Py_ssize_t lo = 0;
     282      Py_ssize_t hi = -1;
     283      PyObject *key = Py_None;
     284  
     285      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 4, 0, argsbuf);
     286      if (!args) {
     287          goto exit;
     288      }
     289      a = args[0];
     290      x = args[1];
     291      if (!noptargs) {
     292          goto skip_optional_pos;
     293      }
     294      if (args[2]) {
     295          {
     296              Py_ssize_t ival = -1;
     297              PyObject *iobj = _PyNumber_Index(args[2]);
     298              if (iobj != NULL) {
     299                  ival = PyLong_AsSsize_t(iobj);
     300                  Py_DECREF(iobj);
     301              }
     302              if (ival == -1 && PyErr_Occurred()) {
     303                  goto exit;
     304              }
     305              lo = ival;
     306          }
     307          if (!--noptargs) {
     308              goto skip_optional_pos;
     309          }
     310      }
     311      if (args[3]) {
     312          if (!_Py_convert_optional_to_ssize_t(args[3], &hi)) {
     313              goto exit;
     314          }
     315          if (!--noptargs) {
     316              goto skip_optional_pos;
     317          }
     318      }
     319  skip_optional_pos:
     320      if (!noptargs) {
     321          goto skip_optional_kwonly;
     322      }
     323      key = args[4];
     324  skip_optional_kwonly:
     325      return_value = _bisect_insort_left_impl(module, a, x, lo, hi, key);
     326  
     327  exit:
     328      return return_value;
     329  }
     330  /*[clinic end generated code: output=ee8c32ff8d3d1fac input=a9049054013a1b77]*/