| 376 | } |
| 377 | |
| 378 | static int LevenshteinDistances_init(LevenshteinDistances *self, PyObject *args, PyObject *kwargs) { |
| 379 | int match = 0, mismatch = 1, open = 1, extend = 1; |
| 380 | PyObject *capabilities_tuple = NULL; |
| 381 | sz_capability_t capabilities = default_hardware_capabilities; |
| 382 | |
| 383 | static char *kwlist[] = {"match", "mismatch", "open", "extend", "capabilities", NULL}; |
| 384 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|iiiiO", kwlist, &match, &mismatch, &open, &extend, |
| 385 | &capabilities_tuple)) |
| 386 | return -1; |
| 387 | |
| 388 | // Validate range of values |
| 389 | if (match < -128 || match > 127) { |
| 390 | PyErr_SetString(PyExc_ValueError, "match cost must fit in 8-bit signed integer"); |
| 391 | return -1; |
| 392 | } |
| 393 | if (mismatch < -128 || mismatch > 127) { |
| 394 | PyErr_SetString(PyExc_ValueError, "mismatch cost must fit in 8-bit signed integer"); |
| 395 | return -1; |
| 396 | } |
| 397 | if (open < -128 || open > 127) { |
| 398 | PyErr_SetString(PyExc_ValueError, "open cost must fit in 8-bit signed integer"); |
| 399 | return -1; |
| 400 | } |
| 401 | if (extend < -128 || extend > 127) { |
| 402 | PyErr_SetString(PyExc_ValueError, "extend cost must fit in 8-bit signed integer"); |
| 403 | return -1; |
| 404 | } |
| 405 | |
| 406 | // Parse capabilities if provided |
| 407 | if (capabilities_tuple) { |
| 408 | if (parse_and_intersect_capabilities(capabilities_tuple, &capabilities) != 0) { return -1; } |
| 409 | } |
| 410 | |
| 411 | char const *error_detail = NULL; |
| 412 | sz_status_t status = |
| 413 | szs_levenshtein_distances_init(match, mismatch, open, extend, NULL, capabilities, &self->handle, &error_detail); |
| 414 | |
| 415 | if (status != sz_success_k) { |
| 416 | set_stringzilla_error(status, error_detail, "Levenshtein distances initialization"); |
| 417 | return -1; |
| 418 | } |
| 419 | |
| 420 | snprintf(self->description, sizeof(self->description), "%d,%d,%d,%d", match, mismatch, open, extend); |
| 421 | self->capabilities = capabilities; |
| 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | static PyObject *LevenshteinDistances_repr(LevenshteinDistances *self) { |
| 426 | return PyUnicode_FromFormat("LevenshteinDistances(match,mismatch,open,extend=%s)", self->description); |
nothing calls this directly
no test coverage detected
searching dependent graphs…