From 21f4014acc41ed7ed9c3335b8c8f99354b81cd14 Mon Sep 17 00:00:00 2001 From: Tal Einat Date: Thu, 24 Apr 2014 19:37:59 +0300 Subject: [PATCH] multiple changes in testing, input validation and implementations --- fuzzysearch/__init__.py | 43 +- fuzzysearch/_generic_search.c | 3619 +++++++++++++++++---------- fuzzysearch/_generic_search.pyx | 113 +- fuzzysearch/generic_search.py | 138 +- tests/test_find_near_matches.py | 12 +- tests/test_generic_search.py | 120 +- tests/test_generic_search_cython.py | 153 +- 7 files changed, 2719 insertions(+), 1479 deletions(-) diff --git a/fuzzysearch/__init__.py b/fuzzysearch/__init__.py index 26e3394..27da0d7 100644 --- a/fuzzysearch/__init__.py +++ b/fuzzysearch/__init__.py @@ -25,8 +25,9 @@ from fuzzysearch.common import Match, get_best_match_in_group, group_matches, \ search_exact from fuzzysearch.levenshtein import find_near_matches_levenshtein from fuzzysearch.substitutions_only import find_near_matches_substitutions -from fuzzysearch.generic_search import \ - find_near_matches_generic_linear_programming +from fuzzysearch.generic_search import find_near_matches_generic, \ + find_near_matches_generic_linear_programming, _check_arguments, \ + _get_max_l_dist def find_near_matches(subsequence, sequence, @@ -45,31 +46,15 @@ def find_near_matches(subsequence, sequence, * the total number of substitutions, insertions and deletions (a.k.a. the Levenshtein distance) """ - if max_l_dist is None: - if ( - max_substitutions is None and - max_insertions is None and - max_deletions is None - ): - raise ValueError('No limitations given!') + _check_arguments(subsequence, sequence, max_substitutions, max_insertions, + max_deletions, max_l_dist) - if max_substitutions is None: - raise ValueError('# substitutions must be limited!') - if max_insertions is None: - raise ValueError('# insertions must be limited!') - if max_deletions is None: - raise ValueError('# deletions must be limited!') + max_l_dist = _get_max_l_dist(max_substitutions, max_insertions, + max_deletions, max_l_dist) # if the limitations are so strict that only exact matches are allowed, # use search_exact() - if ( - max_l_dist == 0 or - ( - max_substitutions == 0 and - max_insertions == 0 and - max_deletions == 0 - ) - ): + if max_l_dist == 0: return [ Match(start_index, start_index + len(subsequence), 0) for start_index in search_exact(subsequence, sequence) @@ -83,7 +68,7 @@ def find_near_matches(subsequence, sequence, # if it is enough to just take into account the maximum Levenshtein # distance, use find_near_matches_levenshtein() - elif max_l_dist is not None and max_l_dist <= min([max_l_dist] + [ + elif max_l_dist <= min([ param for param in [ max_substitutions, max_insertions, max_deletions ] @@ -91,10 +76,8 @@ def find_near_matches(subsequence, sequence, ]): return find_near_matches_levenshtein(subsequence, sequence, max_l_dist) - # if none of the special cases above are met, use the most generic version: - # find_near_matches_generic_linear_programming() + # if none of the special cases above are met, use the most generic version else: - return list(find_near_matches_generic_linear_programming( - subsequence, sequence, - max_substitutions, max_insertions, max_deletions, max_l_dist, - )) + return find_near_matches_generic(subsequence, sequence, + max_substitutions, max_insertions, + max_deletions, max_l_dist) diff --git a/fuzzysearch/_generic_search.c b/fuzzysearch/_generic_search.c index d9fb6a6..25a735e 100644 --- a/fuzzysearch/_generic_search.c +++ b/fuzzysearch/_generic_search.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.20.1 on Sun Apr 20 16:23:32 2014 */ +/* Generated by Cython 0.20.1 on Thu Apr 24 19:36:32 2014 */ #define PY_SSIZE_T_CLEAN #ifndef CYTHON_USE_PYLONG_INTERNALS @@ -532,10 +532,10 @@ static const char *__pyx_f[] = { /*--- Type declarations ---*/ struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming; -struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr; +struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams; struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate; -/* "fuzzysearch/_generic_search.pyx":10 +/* "fuzzysearch/_generic_search.pyx":11 * * * cdef struct GenericSearchCandidate: # <<<<<<<<<<<<<< @@ -551,7 +551,7 @@ struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate { int n_dels; }; -/* "fuzzysearch/_generic_search.pyx":23 +/* "fuzzysearch/_generic_search.pyx":24 * * * def c_find_near_matches_generic_linear_programming(subsequence, sequence, # <<<<<<<<<<<<<< @@ -560,60 +560,82 @@ struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate { */ struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming { PyObject_HEAD - int __pyx_v__subseq_len; - int __pyx_v__subseq_len_minus_one; + size_t __pyx_v__subseq_len; + size_t __pyx_v__subseq_len_minus_one; struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate *__pyx_v__tmp; - PyObject *__pyx_v_alloc_size; - PyObject *__pyx_v_c_max_deletions; - PyObject *__pyx_v_c_max_insertions; - PyObject *__pyx_v_c_max_l_dist; - PyObject *__pyx_v_c_max_substitutions; + size_t __pyx_v_alloc_size; + unsigned int __pyx_v_c_max_deletions; + unsigned int __pyx_v_c_max_insertions; + unsigned int __pyx_v_c_max_l_dist; + unsigned int __pyx_v_c_max_substitutions; char *__pyx_v_c_sequence; char *__pyx_v_c_subsequence; struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate __pyx_v_cand; struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate *__pyx_v_candidates; char __pyx_v_char; - PyObject *__pyx_v_genexpr; int __pyx_v_have_realloced; - unsigned int __pyx_v_index; + size_t __pyx_v_index; PyObject *__pyx_v_max_deletions; PyObject *__pyx_v_max_insertions; PyObject *__pyx_v_max_l_dist; PyObject *__pyx_v_max_substitutions; - PyObject *__pyx_v_maxes_sum; - int __pyx_v_n_cand; - int __pyx_v_n_candidates; - int __pyx_v_n_new_candidates; + size_t __pyx_v_n_cand; + size_t __pyx_v_n_candidates; + size_t __pyx_v_n_new_candidates; PyObject *__pyx_v_n_skipped; struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate *__pyx_v_new_candidates; PyObject *__pyx_v_sequence; PyObject *__pyx_v_subsequence; PyObject *__pyx_t_0; char *__pyx_t_1; - char *__pyx_t_2; - char *__pyx_t_3; + size_t __pyx_t_2; + size_t __pyx_t_3; char *__pyx_t_4; - int __pyx_t_5; - int __pyx_t_6; + char *__pyx_t_5; + char *__pyx_t_6; Py_ssize_t __pyx_t_7; PyObject *__pyx_t_8; PyObject *(*__pyx_t_9)(PyObject *); }; -/* "fuzzysearch/_generic_search.pyx":51 +/* "fuzzysearch/_generic_search.pyx":223 * - * maxes_sum = sum( - * (x if x is not None else 0) # <<<<<<<<<<<<<< - * for x in [max_substitutions, max_insertions, max_deletions] - * ) + * + * def c_find_near_matches_generic_ngrams(subsequence, sequence, # <<<<<<<<<<<<<< + * max_substitutions, max_insertions, + * max_deletions, max_l_dist=None): */ -struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr { +struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams { PyObject_HEAD - struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming *__pyx_outer_scope; - PyObject *__pyx_v_x; - PyObject *__pyx_t_0; - Py_ssize_t __pyx_t_1; + size_t __pyx_v__seq_len; + size_t __pyx_v__subseq_len; + size_t __pyx_v__subseq_len_minus_one; + unsigned int __pyx_v_c_max_deletions; + unsigned int __pyx_v_c_max_insertions; + unsigned int __pyx_v_c_max_l_dist; + unsigned int __pyx_v_c_max_substitutions; + char *__pyx_v_c_sequence; + char *__pyx_v_c_subsequence; + int __pyx_v_index; + PyObject *__pyx_v_match; + char *__pyx_v_match_ptr; + PyObject *__pyx_v_max_deletions; + PyObject *__pyx_v_max_insertions; + PyObject *__pyx_v_max_l_dist; + PyObject *__pyx_v_max_substitutions; + size_t __pyx_v_ngram_len; + size_t __pyx_v_ngram_start; + char *__pyx_v_ngram_str; + PyObject *__pyx_v_sequence; + size_t __pyx_v_small_search_start_index; + PyObject *__pyx_v_subsequence; + Py_ssize_t __pyx_t_0; + PyObject *__pyx_t_1; + PyObject *(*__pyx_t_2)(PyObject *); + PyObject *__pyx_t_3; + Py_ssize_t __pyx_t_4; + PyObject *(*__pyx_t_5)(PyObject *); }; #ifndef CYTHON_REFNANNY @@ -704,8 +726,6 @@ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, \ const char* function_name); /*proto*/ -static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname); - static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name); /*proto*/ #if CYTHON_COMPILING_IN_CPYTHON @@ -726,22 +746,33 @@ static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ +#ifndef __PYX_FORCE_INIT_THREADS + #define __PYX_FORCE_INIT_THREADS 0 +#endif + +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice( + PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop, + PyObject** py_start, PyObject** py_stop, PyObject** py_slice, + int has_cstart, int has_cstop, int wraparound); + #include static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name); /*proto*/ static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); /*proto*/ -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); - -static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *); - -static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *); +static CYTHON_INLINE unsigned int __Pyx_PyInt_As_unsigned_int(PyObject *); static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_int(unsigned int value); +static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *); + +static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *); + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); + static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); @@ -823,7 +854,7 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ /* Module declarations from 'fuzzysearch._generic_search' */ static PyTypeObject *__pyx_ptype_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming = 0; -static PyTypeObject *__pyx_ptype_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr = 0; +static PyTypeObject *__pyx_ptype_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams = 0; #define __Pyx_MODULE_NAME "fuzzysearch._generic_search" int __pyx_module_is_main_fuzzysearch___generic_search = 0; @@ -831,17 +862,16 @@ int __pyx_module_is_main_fuzzysearch___generic_search = 0; static PyObject *__pyx_builtin_ImportError; static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_ValueError; -static PyObject *__pyx_builtin_sum; static PyObject *__pyx_builtin_MemoryError; static PyObject *__pyx_builtin_xrange; -static PyObject *__pyx_pf_11fuzzysearch_15_generic_search_46c_find_near_matches_generic_linear_programming_genexpr(PyObject *__pyx_self); /* proto */ static PyObject *__pyx_pf_11fuzzysearch_15_generic_search_c_find_near_matches_generic_linear_programming(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_subsequence, PyObject *__pyx_v_sequence, PyObject *__pyx_v_max_substitutions, PyObject *__pyx_v_max_insertions, PyObject *__pyx_v_max_deletions, PyObject *__pyx_v_max_l_dist); /* proto */ +static PyObject *__pyx_pf_11fuzzysearch_15_generic_search_3c_find_near_matches_generic_ngrams(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_subsequence, PyObject *__pyx_v_sequence, PyObject *__pyx_v_max_substitutions, PyObject *__pyx_v_max_insertions, PyObject *__pyx_v_max_deletions, PyObject *__pyx_v_max_l_dist); /* proto */ static PyObject *__pyx_tp_new_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ -static PyObject *__pyx_tp_new_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static char __pyx_k_Seq[] = "Seq"; static char __pyx_k_all[] = "__all__"; +static char __pyx_k_end[] = "end"; static char __pyx_k_six[] = "six"; -static char __pyx_k_sum[] = "sum"; static char __pyx_k_sys[] = "sys"; static char __pyx_k_tmp[] = "_tmp"; static char __pyx_k_args[] = "args"; @@ -853,22 +883,27 @@ static char __pyx_k_test[] = "__test__"; static char __pyx_k_Match[] = "Match"; static char __pyx_k_close[] = "close"; static char __pyx_k_index[] = "index"; +static char __pyx_k_match[] = "match"; static char __pyx_k_n_ins[] = "n_ins"; static char __pyx_k_range[] = "range"; static char __pyx_k_start[] = "start"; static char __pyx_k_throw[] = "throw"; static char __pyx_k_import[] = "__import__"; static char __pyx_k_l_dist[] = "l_dist"; +static char __pyx_k_maxint[] = "maxint"; static char __pyx_k_n_cand[] = "n_cand"; static char __pyx_k_n_dels[] = "n_dels"; static char __pyx_k_n_subs[] = "n_subs"; static char __pyx_k_xrange[] = "xrange"; static char __pyx_k_Bio_Seq[] = "Bio.Seq"; -static char __pyx_k_genexpr[] = "genexpr"; +static char __pyx_k_replace[] = "_replace"; +static char __pyx_k_seq_len[] = "_seq_len"; static char __pyx_k_sequence[] = "sequence"; static char __pyx_k_TypeError[] = "TypeError"; -static char __pyx_k_maxes_sum[] = "maxes_sum"; +static char __pyx_k_match_ptr[] = "match_ptr"; static char __pyx_k_n_skipped[] = "n_skipped"; +static char __pyx_k_ngram_len[] = "ngram_len"; +static char __pyx_k_ngram_str[] = "ngram_str"; static char __pyx_k_ValueError[] = "ValueError"; static char __pyx_k_alloc_size[] = "alloc_size"; static char __pyx_k_c_sequence[] = "c_sequence"; @@ -878,6 +913,7 @@ static char __pyx_k_subseq_len[] = "_subseq_len"; static char __pyx_k_ImportError[] = "ImportError"; static char __pyx_k_MemoryError[] = "MemoryError"; static char __pyx_k_binary_type[] = "binary_type"; +static char __pyx_k_ngram_start[] = "ngram_start"; static char __pyx_k_subsequence[] = "subsequence"; static char __pyx_k_c_max_l_dist[] = "c_max_l_dist"; static char __pyx_k_n_candidates[] = "n_candidates"; @@ -895,12 +931,15 @@ static char __pyx_k_max_substitutions[] = "max_substitutions"; static char __pyx_k_fuzzysearch_common[] = "fuzzysearch.common"; static char __pyx_k_c_max_substitutions[] = "c_max_substitutions"; static char __pyx_k_subseq_len_minus_one[] = "_subseq_len_minus_one"; +static char __pyx_k_small_search_start_index[] = "small_search_start_index"; static char __pyx_k_Given_subsequence_is_empty[] = "Given subsequence is empty!"; static char __pyx_k_fuzzysearch__generic_search[] = "fuzzysearch._generic_search"; static char __pyx_k_sequence_is_of_invalid_type_s[] = "sequence is of invalid type %s"; static char __pyx_k_Users_taleinat_dev_fuzzysearch[] = "/Users/taleinat/dev/fuzzysearch/fuzzysearch/_generic_search.pyx"; static char __pyx_k_c_find_near_matches_generic_line[] = "c_find_near_matches_generic_linear_programming"; +static char __pyx_k_c_find_near_matches_generic_ngra[] = "c_find_near_matches_generic_ngrams"; static char __pyx_k_subsequence_is_of_invalid_type_s[] = "subsequence is of invalid type %s"; +static char __pyx_k_the_subsequence_length_must_be_g[] = "the subsequence length must be greater than max_l_dist"; static PyObject *__pyx_n_s_ALLOWED_TYPES; static PyObject *__pyx_n_s_Bio_Seq; static PyObject *__pyx_kp_s_Given_subsequence_is_empty; @@ -916,6 +955,7 @@ static PyObject *__pyx_n_s_alloc_size; static PyObject *__pyx_n_s_args; static PyObject *__pyx_n_s_binary_type; static PyObject *__pyx_n_s_c_find_near_matches_generic_line; +static PyObject *__pyx_n_s_c_find_near_matches_generic_ngra; static PyObject *__pyx_n_s_c_max_deletions; static PyObject *__pyx_n_s_c_max_insertions; static PyObject *__pyx_n_s_c_max_l_dist; @@ -926,19 +966,21 @@ static PyObject *__pyx_n_s_cand; static PyObject *__pyx_n_s_candidates; static PyObject *__pyx_n_s_char; static PyObject *__pyx_n_s_close; +static PyObject *__pyx_n_s_end; static PyObject *__pyx_n_s_fuzzysearch__generic_search; static PyObject *__pyx_n_s_fuzzysearch_common; -static PyObject *__pyx_n_s_genexpr; static PyObject *__pyx_n_s_have_realloced; static PyObject *__pyx_n_s_import; static PyObject *__pyx_n_s_index; static PyObject *__pyx_n_s_l_dist; static PyObject *__pyx_n_s_main; +static PyObject *__pyx_n_s_match; +static PyObject *__pyx_n_s_match_ptr; static PyObject *__pyx_n_s_max_deletions; static PyObject *__pyx_n_s_max_insertions; static PyObject *__pyx_n_s_max_l_dist; static PyObject *__pyx_n_s_max_substitutions; -static PyObject *__pyx_n_s_maxes_sum; +static PyObject *__pyx_n_s_maxint; static PyObject *__pyx_n_s_n_cand; static PyObject *__pyx_n_s_n_candidates; static PyObject *__pyx_n_s_n_dels; @@ -947,32 +989,42 @@ static PyObject *__pyx_n_s_n_new_candidates; static PyObject *__pyx_n_s_n_skipped; static PyObject *__pyx_n_s_n_subs; static PyObject *__pyx_n_s_new_candidates; +static PyObject *__pyx_n_s_ngram_len; +static PyObject *__pyx_n_s_ngram_start; +static PyObject *__pyx_n_s_ngram_str; static PyObject *__pyx_n_s_range; +static PyObject *__pyx_n_s_replace; static PyObject *__pyx_n_s_send; +static PyObject *__pyx_n_s_seq_len; static PyObject *__pyx_n_s_sequence; static PyObject *__pyx_kp_s_sequence_is_of_invalid_type_s; static PyObject *__pyx_n_s_six; +static PyObject *__pyx_n_s_small_search_start_index; static PyObject *__pyx_n_s_start; static PyObject *__pyx_n_s_subseq_index; static PyObject *__pyx_n_s_subseq_len; static PyObject *__pyx_n_s_subseq_len_minus_one; static PyObject *__pyx_n_s_subsequence; static PyObject *__pyx_kp_s_subsequence_is_of_invalid_type_s; -static PyObject *__pyx_n_s_sum; static PyObject *__pyx_n_s_sys; static PyObject *__pyx_n_s_test; +static PyObject *__pyx_kp_s_the_subsequence_length_must_be_g; static PyObject *__pyx_n_s_throw; static PyObject *__pyx_n_s_tmp; static PyObject *__pyx_n_s_xrange; static PyObject *__pyx_int_0; static PyObject *__pyx_int_1; -static PyObject *__pyx_int_2; +static PyObject *__pyx_int_536870912; static PyObject *__pyx_tuple_; static PyObject *__pyx_tuple__2; -static PyObject *__pyx_codeobj__3; +static PyObject *__pyx_tuple__3; +static PyObject *__pyx_tuple__4; +static PyObject *__pyx_tuple__6; +static PyObject *__pyx_codeobj__5; +static PyObject *__pyx_codeobj__7; static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ -/* "fuzzysearch/_generic_search.pyx":23 +/* "fuzzysearch/_generic_search.pyx":24 * * * def c_find_near_matches_generic_linear_programming(subsequence, sequence, # <<<<<<<<<<<<<< @@ -1001,7 +1053,7 @@ static PyObject *__pyx_pw_11fuzzysearch_15_generic_search_1c_find_near_matches_g static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_subsequence,&__pyx_n_s_sequence,&__pyx_n_s_max_substitutions,&__pyx_n_s_max_insertions,&__pyx_n_s_max_deletions,&__pyx_n_s_max_l_dist,0}; PyObject* values[6] = {0,0,0,0,0,0}; - /* "fuzzysearch/_generic_search.pyx":27 + /* "fuzzysearch/_generic_search.pyx":28 * max_insertions, * max_deletions, * max_l_dist=None): # <<<<<<<<<<<<<< @@ -1030,22 +1082,22 @@ static PyObject *__pyx_pw_11fuzzysearch_15_generic_search_1c_find_near_matches_g case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sequence)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("c_find_near_matches_generic_linear_programming", 0, 5, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("c_find_near_matches_generic_linear_programming", 0, 5, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_substitutions)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("c_find_near_matches_generic_linear_programming", 0, 5, 6, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("c_find_near_matches_generic_linear_programming", 0, 5, 6, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 3: if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_insertions)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("c_find_near_matches_generic_linear_programming", 0, 5, 6, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("c_find_near_matches_generic_linear_programming", 0, 5, 6, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 4: if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_deletions)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("c_find_near_matches_generic_linear_programming", 0, 5, 6, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("c_find_near_matches_generic_linear_programming", 0, 5, 6, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 5: if (kw_args > 0) { @@ -1054,7 +1106,7 @@ static PyObject *__pyx_pw_11fuzzysearch_15_generic_search_1c_find_near_matches_g } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "c_find_near_matches_generic_linear_programming") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "c_find_near_matches_generic_linear_programming") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -1077,7 +1129,7 @@ static PyObject *__pyx_pw_11fuzzysearch_15_generic_search_1c_find_near_matches_g } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("c_find_near_matches_generic_linear_programming", 0, 5, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("c_find_near_matches_generic_linear_programming", 0, 5, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("fuzzysearch._generic_search.c_find_near_matches_generic_linear_programming", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -1085,7 +1137,7 @@ static PyObject *__pyx_pw_11fuzzysearch_15_generic_search_1c_find_near_matches_g __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_11fuzzysearch_15_generic_search_c_find_near_matches_generic_linear_programming(__pyx_self, __pyx_v_subsequence, __pyx_v_sequence, __pyx_v_max_substitutions, __pyx_v_max_insertions, __pyx_v_max_deletions, __pyx_v_max_l_dist); - /* "fuzzysearch/_generic_search.pyx":23 + /* "fuzzysearch/_generic_search.pyx":24 * * * def c_find_near_matches_generic_linear_programming(subsequence, sequence, # <<<<<<<<<<<<<< @@ -1097,167 +1149,6 @@ static PyObject *__pyx_pw_11fuzzysearch_15_generic_search_1c_find_near_matches_g __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_46c_find_near_matches_generic_linear_programming_2generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ - -/* "fuzzysearch/_generic_search.pyx":51 - * - * maxes_sum = sum( - * (x if x is not None else 0) # <<<<<<<<<<<<<< - * for x in [max_substitutions, max_insertions, max_deletions] - * ) - */ - -static PyObject *__pyx_pf_11fuzzysearch_15_generic_search_46c_find_near_matches_generic_linear_programming_genexpr(PyObject *__pyx_self) { - struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr *__pyx_cur_scope; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("genexpr", 0); - __pyx_cur_scope = (struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr *)__pyx_tp_new_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr(__pyx_ptype_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr, __pyx_empty_tuple, NULL); - if (unlikely(!__pyx_cur_scope)) { - __Pyx_RefNannyFinishContext(); - return NULL; - } - __Pyx_GOTREF(__pyx_cur_scope); - __pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming *) __pyx_self; - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope)); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope); - { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_11fuzzysearch_15_generic_search_46c_find_near_matches_generic_linear_programming_2generator1, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_cur_scope); - __Pyx_RefNannyFinishContext(); - return (PyObject *) gen; - } - - /* function exit code */ - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_AddTraceback("fuzzysearch._generic_search.c_find_near_matches_generic_linear_programming.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_46c_find_near_matches_generic_linear_programming_2generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ -{ - struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr *__pyx_cur_scope = ((struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr *)__pyx_generator->closure); - PyObject *__pyx_r = NULL; - PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - Py_ssize_t __pyx_t_3; - int __pyx_t_4; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("None", 0); - switch (__pyx_generator->resume_label) { - case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L6_resume_from_yield; - default: /* CPython raises the right error here */ - __Pyx_RefNannyFinishContext(); - return NULL; - } - __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - - /* "fuzzysearch/_generic_search.pyx":52 - * maxes_sum = sum( - * (x if x is not None else 0) - * for x in [max_substitutions, max_insertions, max_deletions] # <<<<<<<<<<<<<< - * ) - * if max_l_dist is None or max_l_dist >= maxes_sum: - */ - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_max_substitutions)) { __Pyx_RaiseClosureNameError("max_substitutions"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_max_insertions)) { __Pyx_RaiseClosureNameError("max_insertions"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_max_deletions)) { __Pyx_RaiseClosureNameError("max_deletions"); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_max_substitutions); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_max_substitutions); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_max_substitutions); - __Pyx_INCREF(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_max_insertions); - PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_max_insertions); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_max_insertions); - __Pyx_INCREF(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_max_deletions); - PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_max_deletions); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_max_deletions); - __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - for (;;) { - if (__pyx_t_3 >= 3) break; - #if CYTHON_COMPILING_IN_CPYTHON - __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - #endif - __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x); - __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_x, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - - /* "fuzzysearch/_generic_search.pyx":51 - * - * maxes_sum = sum( - * (x if x is not None else 0) # <<<<<<<<<<<<<< - * for x in [max_substitutions, max_insertions, max_deletions] - * ) - */ - __pyx_t_4 = (__pyx_cur_scope->__pyx_v_x != Py_None); - if ((__pyx_t_4 != 0)) { - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_x); - __pyx_t_1 = __pyx_cur_scope->__pyx_v_x; - } else { - __Pyx_INCREF(__pyx_int_0); - __pyx_t_1 = __pyx_int_0; - } - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; - __Pyx_XGIVEREF(__pyx_t_2); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L6_resume_from_yield:; - __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; - __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_2); - __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - - /* function exit code */ - PyErr_SetNone(PyExc_StopIteration); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_XDECREF(__pyx_t_2); - __Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; - __Pyx_Generator_clear((PyObject*)__pyx_generator); - __Pyx_RefNannyFinishContext(); - return NULL; -} - -/* "fuzzysearch/_generic_search.pyx":23 - * - * - * def c_find_near_matches_generic_linear_programming(subsequence, sequence, # <<<<<<<<<<<<<< - * max_substitutions, - * max_insertions, - */ static PyObject *__pyx_pf_11fuzzysearch_15_generic_search_c_find_near_matches_generic_linear_programming(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_subsequence, PyObject *__pyx_v_sequence, PyObject *__pyx_v_max_substitutions, PyObject *__pyx_v_max_insertions, PyObject *__pyx_v_max_deletions, PyObject *__pyx_v_max_l_dist) { struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming *__pyx_cur_scope; @@ -1292,7 +1183,7 @@ static PyObject *__pyx_pf_11fuzzysearch_15_generic_search_c_find_near_matches_ge __Pyx_INCREF(__pyx_cur_scope->__pyx_v_max_l_dist); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_max_l_dist); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_11fuzzysearch_15_generic_search_2generator, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_11fuzzysearch_15_generic_search_2generator, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -1320,34 +1211,35 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener int __pyx_t_3; PyObject *__pyx_t_4 = NULL; Py_ssize_t __pyx_t_5; - int __pyx_t_6; - char *__pyx_t_7; - long __pyx_t_8; - long __pyx_t_9; - long __pyx_t_10; + unsigned int __pyx_t_6; + unsigned int __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + char *__pyx_t_10; size_t __pyx_t_11; - char *__pyx_t_12; - char *__pyx_t_13; + long __pyx_t_12; + size_t __pyx_t_13; char *__pyx_t_14; - struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate __pyx_t_15; - int __pyx_t_16; - int __pyx_t_17; + char *__pyx_t_15; + char *__pyx_t_16; + struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate __pyx_t_17; PyObject *__pyx_t_18 = NULL; PyObject *__pyx_t_19 = NULL; - PyObject *__pyx_t_20 = NULL; - PyObject *__pyx_t_21 = NULL; - int __pyx_t_22; + int __pyx_t_20; + int __pyx_t_21; + unsigned int __pyx_t_22; PyObject *(*__pyx_t_23)(PyObject *); PyObject *__pyx_t_24 = NULL; Py_ssize_t __pyx_t_25; int __pyx_t_26; - char const *__pyx_t_27; - PyObject *__pyx_t_28 = NULL; + int __pyx_t_27; + char const *__pyx_t_28; PyObject *__pyx_t_29 = NULL; PyObject *__pyx_t_30 = NULL; PyObject *__pyx_t_31 = NULL; PyObject *__pyx_t_32 = NULL; PyObject *__pyx_t_33 = NULL; + PyObject *__pyx_t_34 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -1355,361 +1247,337 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L21_resume_from_yield; - case 2: goto __pyx_L27_resume_from_yield; - case 3: goto __pyx_L31_resume_from_yield; - case 4: goto __pyx_L33_resume_from_yield; - case 5: goto __pyx_L39_resume_from_yield; + case 1: goto __pyx_L20_resume_from_yield; + case 2: goto __pyx_L26_resume_from_yield; + case 3: goto __pyx_L30_resume_from_yield; + case 4: goto __pyx_L32_resume_from_yield; + case 5: goto __pyx_L38_resume_from_yield; default: /* CPython raises the right error here */ __Pyx_RefNannyFinishContext(); return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "fuzzysearch/_generic_search.pyx":38 + /* "fuzzysearch/_generic_search.pyx":39 * * the total number of substitutions, insertions and deletions * """ * if not isinstance(sequence, ALLOWED_TYPES): # <<<<<<<<<<<<<< * raise TypeError('sequence is of invalid type %s' % type(subsequence)) * if not isinstance(subsequence, ALLOWED_TYPES): */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_ALLOWED_TYPES); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_ALLOWED_TYPES); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_IsInstance(__pyx_cur_scope->__pyx_v_sequence, __pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_IsInstance(__pyx_cur_scope->__pyx_v_sequence, __pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = ((!(__pyx_t_2 != 0)) != 0); if (__pyx_t_3) { - /* "fuzzysearch/_generic_search.pyx":39 + /* "fuzzysearch/_generic_search.pyx":40 * """ * if not isinstance(sequence, ALLOWED_TYPES): * raise TypeError('sequence is of invalid type %s' % type(subsequence)) # <<<<<<<<<<<<<< * if not isinstance(subsequence, ALLOWED_TYPES): * raise TypeError('subsequence is of invalid type %s' % type(subsequence)) */ - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_sequence_is_of_invalid_type_s, ((PyObject *)Py_TYPE(__pyx_cur_scope->__pyx_v_subsequence))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_sequence_is_of_invalid_type_s, ((PyObject *)Py_TYPE(__pyx_cur_scope->__pyx_v_subsequence))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - /* "fuzzysearch/_generic_search.pyx":40 + /* "fuzzysearch/_generic_search.pyx":41 * if not isinstance(sequence, ALLOWED_TYPES): * raise TypeError('sequence is of invalid type %s' % type(subsequence)) * if not isinstance(subsequence, ALLOWED_TYPES): # <<<<<<<<<<<<<< * raise TypeError('subsequence is of invalid type %s' % type(subsequence)) * */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_ALLOWED_TYPES); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_ALLOWED_TYPES); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_IsInstance(__pyx_cur_scope->__pyx_v_subsequence, __pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_IsInstance(__pyx_cur_scope->__pyx_v_subsequence, __pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_2 = ((!(__pyx_t_3 != 0)) != 0); if (__pyx_t_2) { - /* "fuzzysearch/_generic_search.pyx":41 + /* "fuzzysearch/_generic_search.pyx":42 * raise TypeError('sequence is of invalid type %s' % type(subsequence)) * if not isinstance(subsequence, ALLOWED_TYPES): * raise TypeError('subsequence is of invalid type %s' % type(subsequence)) # <<<<<<<<<<<<<< * * if not subsequence: */ - __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_subsequence_is_of_invalid_type_s, ((PyObject *)Py_TYPE(__pyx_cur_scope->__pyx_v_subsequence))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_subsequence_is_of_invalid_type_s, ((PyObject *)Py_TYPE(__pyx_cur_scope->__pyx_v_subsequence))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - /* "fuzzysearch/_generic_search.pyx":43 + /* "fuzzysearch/_generic_search.pyx":44 * raise TypeError('subsequence is of invalid type %s' % type(subsequence)) * * if not subsequence: # <<<<<<<<<<<<<< * raise ValueError('Given subsequence is empty!') * */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_subsequence); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_subsequence); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_3 = ((!__pyx_t_2) != 0); if (__pyx_t_3) { - /* "fuzzysearch/_generic_search.pyx":44 + /* "fuzzysearch/_generic_search.pyx":45 * * if not subsequence: * raise ValueError('Given subsequence is empty!') # <<<<<<<<<<<<<< * * # optimization: prepare some often used things in advance */ - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - /* "fuzzysearch/_generic_search.pyx":47 + /* "fuzzysearch/_generic_search.pyx":48 * * # optimization: prepare some often used things in advance - * cdef int _subseq_len = len(subsequence) # <<<<<<<<<<<<<< - * cdef int _subseq_len_minus_one = _subseq_len - 1 + * cdef size_t _subseq_len = len(subsequence) # <<<<<<<<<<<<<< + * cdef size_t _subseq_len_minus_one = _subseq_len - 1 * */ - __pyx_t_5 = PyObject_Length(__pyx_cur_scope->__pyx_v_subsequence); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyObject_Length(__pyx_cur_scope->__pyx_v_subsequence); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_cur_scope->__pyx_v__subseq_len = __pyx_t_5; - /* "fuzzysearch/_generic_search.pyx":48 + /* "fuzzysearch/_generic_search.pyx":49 * # optimization: prepare some often used things in advance - * cdef int _subseq_len = len(subsequence) - * cdef int _subseq_len_minus_one = _subseq_len - 1 # <<<<<<<<<<<<<< + * cdef size_t _subseq_len = len(subsequence) + * cdef size_t _subseq_len_minus_one = _subseq_len - 1 # <<<<<<<<<<<<<< * - * maxes_sum = sum( + * cdef unsigned int c_max_substitutions = max_substitutions if max_substitutions is not None else (1<<29) */ __pyx_cur_scope->__pyx_v__subseq_len_minus_one = (__pyx_cur_scope->__pyx_v__subseq_len - 1); /* "fuzzysearch/_generic_search.pyx":51 + * cdef size_t _subseq_len_minus_one = _subseq_len - 1 * - * maxes_sum = sum( - * (x if x is not None else 0) # <<<<<<<<<<<<<< - * for x in [max_substitutions, max_insertions, max_deletions] - * ) + * cdef unsigned int c_max_substitutions = max_substitutions if max_substitutions is not None else (1<<29) # <<<<<<<<<<<<<< + * cdef unsigned int c_max_insertions = max_insertions if max_insertions is not None else (1<<29) + * cdef unsigned int c_max_deletions = max_deletions if max_deletions is not None else (1<<29) */ - __pyx_t_1 = __pyx_pf_11fuzzysearch_15_generic_search_46c_find_near_matches_generic_linear_programming_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - - /* "fuzzysearch/_generic_search.pyx":50 - * cdef int _subseq_len_minus_one = _subseq_len - 1 - * - * maxes_sum = sum( # <<<<<<<<<<<<<< - * (x if x is not None else 0) - * for x in [max_substitutions, max_insertions, max_deletions] - */ - __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_GIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_v_maxes_sum = __pyx_t_1; - __pyx_t_1 = 0; - - /* "fuzzysearch/_generic_search.pyx":54 - * for x in [max_substitutions, max_insertions, max_deletions] - * ) - * if max_l_dist is None or max_l_dist >= maxes_sum: # <<<<<<<<<<<<<< - * max_l_dist = maxes_sum - * - */ - __pyx_t_3 = (__pyx_cur_scope->__pyx_v_max_l_dist == Py_None); - if (!__pyx_t_3) { - __pyx_t_1 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_max_l_dist, __pyx_cur_scope->__pyx_v_maxes_sum, Py_GE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_6 = __pyx_t_2; + __pyx_t_3 = (__pyx_cur_scope->__pyx_v_max_substitutions != Py_None); + if ((__pyx_t_3 != 0)) { + __pyx_t_7 = __Pyx_PyInt_As_unsigned_int(__pyx_cur_scope->__pyx_v_max_substitutions); if (unlikely((__pyx_t_7 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __pyx_t_7; } else { - __pyx_t_6 = __pyx_t_3; + __pyx_t_6 = 536870912; } - if (__pyx_t_6) { + __pyx_cur_scope->__pyx_v_c_max_substitutions = __pyx_t_6; - /* "fuzzysearch/_generic_search.pyx":55 - * ) - * if max_l_dist is None or max_l_dist >= maxes_sum: - * max_l_dist = maxes_sum # <<<<<<<<<<<<<< + /* "fuzzysearch/_generic_search.pyx":52 + * + * cdef unsigned int c_max_substitutions = max_substitutions if max_substitutions is not None else (1<<29) + * cdef unsigned int c_max_insertions = max_insertions if max_insertions is not None else (1<<29) # <<<<<<<<<<<<<< + * cdef unsigned int c_max_deletions = max_deletions if max_deletions is not None else (1<<29) * - * cdef c_max_l_dist = max_l_dist */ - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_maxes_sum); - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_max_l_dist); - __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_max_l_dist, __pyx_cur_scope->__pyx_v_maxes_sum); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_maxes_sum); - goto __pyx_L7; + __pyx_t_3 = (__pyx_cur_scope->__pyx_v_max_insertions != Py_None); + if ((__pyx_t_3 != 0)) { + __pyx_t_7 = __Pyx_PyInt_As_unsigned_int(__pyx_cur_scope->__pyx_v_max_insertions); if (unlikely((__pyx_t_7 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __pyx_t_7; + } else { + __pyx_t_6 = 536870912; } - __pyx_L7:; + __pyx_cur_scope->__pyx_v_c_max_insertions = __pyx_t_6; - /* "fuzzysearch/_generic_search.pyx":57 - * max_l_dist = maxes_sum + /* "fuzzysearch/_generic_search.pyx":53 + * cdef unsigned int c_max_substitutions = max_substitutions if max_substitutions is not None else (1<<29) + * cdef unsigned int c_max_insertions = max_insertions if max_insertions is not None else (1<<29) + * cdef unsigned int c_max_deletions = max_deletions if max_deletions is not None else (1<<29) # <<<<<<<<<<<<<< * - * cdef c_max_l_dist = max_l_dist # <<<<<<<<<<<<<< - * cdef c_max_substitutions = max_substitutions - * cdef c_max_insertions = max_insertions + * # TODO: write a good comment */ - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_max_l_dist); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_max_l_dist); - __pyx_cur_scope->__pyx_v_c_max_l_dist = __pyx_cur_scope->__pyx_v_max_l_dist; + __pyx_t_3 = (__pyx_cur_scope->__pyx_v_max_deletions != Py_None); + if ((__pyx_t_3 != 0)) { + __pyx_t_7 = __Pyx_PyInt_As_unsigned_int(__pyx_cur_scope->__pyx_v_max_deletions); if (unlikely((__pyx_t_7 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __pyx_t_7; + } else { + __pyx_t_6 = 536870912; + } + __pyx_cur_scope->__pyx_v_c_max_deletions = __pyx_t_6; /* "fuzzysearch/_generic_search.pyx":58 - * - * cdef c_max_l_dist = max_l_dist - * cdef c_max_substitutions = max_substitutions # <<<<<<<<<<<<<< - * cdef c_max_insertions = max_insertions - * cdef c_max_deletions = max_deletions - */ - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_max_substitutions); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_max_substitutions); - __pyx_cur_scope->__pyx_v_c_max_substitutions = __pyx_cur_scope->__pyx_v_max_substitutions; - - /* "fuzzysearch/_generic_search.pyx":59 - * cdef c_max_l_dist = max_l_dist - * cdef c_max_substitutions = max_substitutions - * cdef c_max_insertions = max_insertions # <<<<<<<<<<<<<< - * cdef c_max_deletions = max_deletions + * cdef unsigned int c_max_l_dist = min( + * max_l_dist if max_l_dist is not None else (1<<29), + * c_max_substitutions + c_max_insertions + c_max_deletions, # <<<<<<<<<<<<<< + * ) * */ - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_max_insertions); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_max_insertions); - __pyx_cur_scope->__pyx_v_c_max_insertions = __pyx_cur_scope->__pyx_v_max_insertions; + __pyx_t_6 = ((__pyx_cur_scope->__pyx_v_c_max_substitutions + __pyx_cur_scope->__pyx_v_c_max_insertions) + __pyx_cur_scope->__pyx_v_c_max_deletions); - /* "fuzzysearch/_generic_search.pyx":60 - * cdef c_max_substitutions = max_substitutions - * cdef c_max_insertions = max_insertions - * cdef c_max_deletions = max_deletions # <<<<<<<<<<<<<< - * - * cdef alloc_size + /* "fuzzysearch/_generic_search.pyx":57 + * # TODO: write a good comment + * cdef unsigned int c_max_l_dist = min( + * max_l_dist if max_l_dist is not None else (1<<29), # <<<<<<<<<<<<<< + * c_max_substitutions + c_max_insertions + c_max_deletions, + * ) */ - __Pyx_INCREF(__pyx_cur_scope->__pyx_v_max_deletions); - __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_max_deletions); - __pyx_cur_scope->__pyx_v_c_max_deletions = __pyx_cur_scope->__pyx_v_max_deletions; + __pyx_t_3 = (__pyx_cur_scope->__pyx_v_max_l_dist != Py_None); + if ((__pyx_t_3 != 0)) { + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_max_l_dist); + __pyx_t_1 = __pyx_cur_scope->__pyx_v_max_l_dist; + } else { + __Pyx_INCREF(__pyx_int_536870912); + __pyx_t_1 = __pyx_int_536870912; + } - /* "fuzzysearch/_generic_search.pyx":67 + /* "fuzzysearch/_generic_search.pyx":58 + * cdef unsigned int c_max_l_dist = min( + * max_l_dist if max_l_dist is not None else (1<<29), + * c_max_substitutions + c_max_insertions + c_max_deletions, # <<<<<<<<<<<<<< + * ) + * + */ + __pyx_t_8 = __Pyx_PyInt_From_unsigned_int(__pyx_t_6); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = PyObject_RichCompare(__pyx_t_8, __pyx_t_1, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (__pyx_t_3) { + __pyx_t_9 = __Pyx_PyInt_From_unsigned_int(__pyx_t_6); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_4 = __pyx_t_9; + __pyx_t_9 = 0; + } else { + __Pyx_INCREF(__pyx_t_1); + __pyx_t_4 = __pyx_t_1; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_6 = __Pyx_PyInt_As_unsigned_int(__pyx_t_4); if (unlikely((__pyx_t_6 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_cur_scope->__pyx_v_c_max_l_dist = __pyx_t_6; + + /* "fuzzysearch/_generic_search.pyx":66 * cdef GenericSearchCandidate* _tmp * cdef GenericSearchCandidate cand - * cdef int n_candidates = 0 # <<<<<<<<<<<<<< - * cdef int n_new_candidates = 0 - * cdef int n_cand + * cdef size_t n_candidates = 0 # <<<<<<<<<<<<<< + * cdef size_t n_new_candidates = 0 + * cdef size_t n_cand */ __pyx_cur_scope->__pyx_v_n_candidates = 0; - /* "fuzzysearch/_generic_search.pyx":68 + /* "fuzzysearch/_generic_search.pyx":67 * cdef GenericSearchCandidate cand - * cdef int n_candidates = 0 - * cdef int n_new_candidates = 0 # <<<<<<<<<<<<<< - * cdef int n_cand + * cdef size_t n_candidates = 0 + * cdef size_t n_new_candidates = 0 # <<<<<<<<<<<<<< + * cdef size_t n_cand * */ __pyx_cur_scope->__pyx_v_n_new_candidates = 0; - /* "fuzzysearch/_generic_search.pyx":71 - * cdef int n_cand + /* "fuzzysearch/_generic_search.pyx":70 + * cdef size_t n_cand * * cdef char* c_sequence = sequence # <<<<<<<<<<<<<< * cdef char* c_subsequence = subsequence * cdef char char */ - __pyx_t_7 = __Pyx_PyObject_AsString(__pyx_cur_scope->__pyx_v_sequence); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_cur_scope->__pyx_v_c_sequence = __pyx_t_7; + __pyx_t_10 = __Pyx_PyObject_AsString(__pyx_cur_scope->__pyx_v_sequence); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_c_sequence = __pyx_t_10; - /* "fuzzysearch/_generic_search.pyx":72 + /* "fuzzysearch/_generic_search.pyx":71 * * cdef char* c_sequence = sequence * cdef char* c_subsequence = subsequence # <<<<<<<<<<<<<< * cdef char char * */ - __pyx_t_7 = __Pyx_PyObject_AsString(__pyx_cur_scope->__pyx_v_subsequence); if (unlikely((!__pyx_t_7) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_cur_scope->__pyx_v_c_subsequence = __pyx_t_7; + __pyx_t_10 = __Pyx_PyObject_AsString(__pyx_cur_scope->__pyx_v_subsequence); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_c_subsequence = __pyx_t_10; - /* "fuzzysearch/_generic_search.pyx":75 + /* "fuzzysearch/_generic_search.pyx":74 * cdef char char * * alloc_size = min(10, _subseq_len * 3 + 1) # <<<<<<<<<<<<<< * candidates = malloc(alloc_size * sizeof(GenericSearchCandidate)) * if candidates is NULL: */ - __pyx_t_8 = ((__pyx_cur_scope->__pyx_v__subseq_len * 3) + 1); - __pyx_t_9 = 10; - if (((__pyx_t_8 < __pyx_t_9) != 0)) { - __pyx_t_10 = __pyx_t_8; + __pyx_t_11 = ((__pyx_cur_scope->__pyx_v__subseq_len * 3) + 1); + __pyx_t_12 = 10; + if (((__pyx_t_11 < __pyx_t_12) != 0)) { + __pyx_t_13 = __pyx_t_11; } else { - __pyx_t_10 = __pyx_t_9; + __pyx_t_13 = __pyx_t_12; } - __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_t_10); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_v_alloc_size = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_cur_scope->__pyx_v_alloc_size = __pyx_t_13; - /* "fuzzysearch/_generic_search.pyx":76 + /* "fuzzysearch/_generic_search.pyx":75 * * alloc_size = min(10, _subseq_len * 3 + 1) * candidates = malloc(alloc_size * sizeof(GenericSearchCandidate)) # <<<<<<<<<<<<<< * if candidates is NULL: * raise MemoryError() */ - __pyx_t_1 = __Pyx_PyInt_FromSize_t((sizeof(struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyNumber_Multiply(__pyx_cur_scope->__pyx_v_alloc_size, __pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_11 = __Pyx_PyInt_As_size_t(__pyx_t_4); if (unlikely((__pyx_t_11 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_cur_scope->__pyx_v_candidates = ((struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate *)malloc(__pyx_t_11)); + __pyx_cur_scope->__pyx_v_candidates = ((struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate *)malloc((__pyx_cur_scope->__pyx_v_alloc_size * (sizeof(struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate))))); - /* "fuzzysearch/_generic_search.pyx":77 + /* "fuzzysearch/_generic_search.pyx":76 * alloc_size = min(10, _subseq_len * 3 + 1) * candidates = malloc(alloc_size * sizeof(GenericSearchCandidate)) * if candidates is NULL: # <<<<<<<<<<<<<< * raise MemoryError() * new_candidates = malloc(alloc_size * sizeof(GenericSearchCandidate)) */ - __pyx_t_6 = ((__pyx_cur_scope->__pyx_v_candidates == NULL) != 0); - if (__pyx_t_6) { + __pyx_t_3 = ((__pyx_cur_scope->__pyx_v_candidates == NULL) != 0); + if (__pyx_t_3) { - /* "fuzzysearch/_generic_search.pyx":78 + /* "fuzzysearch/_generic_search.pyx":77 * candidates = malloc(alloc_size * sizeof(GenericSearchCandidate)) * if candidates is NULL: * raise MemoryError() # <<<<<<<<<<<<<< * new_candidates = malloc(alloc_size * sizeof(GenericSearchCandidate)) * if candidates is NULL: */ - PyErr_NoMemory(); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + PyErr_NoMemory(); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - /* "fuzzysearch/_generic_search.pyx":79 + /* "fuzzysearch/_generic_search.pyx":78 * if candidates is NULL: * raise MemoryError() * new_candidates = malloc(alloc_size * sizeof(GenericSearchCandidate)) # <<<<<<<<<<<<<< * if candidates is NULL: * free(candidates) */ - __pyx_t_4 = __Pyx_PyInt_FromSize_t((sizeof(struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = PyNumber_Multiply(__pyx_cur_scope->__pyx_v_alloc_size, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_11 = __Pyx_PyInt_As_size_t(__pyx_t_1); if (unlikely((__pyx_t_11 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_cur_scope->__pyx_v_new_candidates = ((struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate *)malloc(__pyx_t_11)); + __pyx_cur_scope->__pyx_v_new_candidates = ((struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate *)malloc((__pyx_cur_scope->__pyx_v_alloc_size * (sizeof(struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate))))); - /* "fuzzysearch/_generic_search.pyx":80 + /* "fuzzysearch/_generic_search.pyx":79 * raise MemoryError() * new_candidates = malloc(alloc_size * sizeof(GenericSearchCandidate)) * if candidates is NULL: # <<<<<<<<<<<<<< * free(candidates) * raise MemoryError() */ - __pyx_t_6 = ((__pyx_cur_scope->__pyx_v_candidates == NULL) != 0); - if (__pyx_t_6) { + __pyx_t_3 = ((__pyx_cur_scope->__pyx_v_candidates == NULL) != 0); + if (__pyx_t_3) { - /* "fuzzysearch/_generic_search.pyx":81 + /* "fuzzysearch/_generic_search.pyx":80 * new_candidates = malloc(alloc_size * sizeof(GenericSearchCandidate)) * if candidates is NULL: * free(candidates) # <<<<<<<<<<<<<< @@ -1718,27 +1586,27 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener */ free(__pyx_cur_scope->__pyx_v_candidates); - /* "fuzzysearch/_generic_search.pyx":82 + /* "fuzzysearch/_generic_search.pyx":81 * if candidates is NULL: * free(candidates) * raise MemoryError() # <<<<<<<<<<<<<< * - * cdef unsigned int index + * cdef size_t index */ - PyErr_NoMemory(); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + PyErr_NoMemory(); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - /* "fuzzysearch/_generic_search.pyx":85 + /* "fuzzysearch/_generic_search.pyx":84 * - * cdef unsigned int index + * cdef size_t index * try: # <<<<<<<<<<<<<< * index = 0 * have_realloced = False */ /*try:*/ { - /* "fuzzysearch/_generic_search.pyx":86 - * cdef unsigned int index + /* "fuzzysearch/_generic_search.pyx":85 + * cdef size_t index * try: * index = 0 # <<<<<<<<<<<<<< * have_realloced = False @@ -1746,7 +1614,7 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener */ __pyx_cur_scope->__pyx_v_index = 0; - /* "fuzzysearch/_generic_search.pyx":87 + /* "fuzzysearch/_generic_search.pyx":86 * try: * index = 0 * have_realloced = False # <<<<<<<<<<<<<< @@ -1755,38 +1623,38 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener */ __pyx_cur_scope->__pyx_v_have_realloced = 0; - /* "fuzzysearch/_generic_search.pyx":88 + /* "fuzzysearch/_generic_search.pyx":87 * index = 0 * have_realloced = False * for char in c_sequence[:len(sequence)]: # <<<<<<<<<<<<<< * candidates[n_candidates] = GenericSearchCandidate(index, 0, 0, 0, 0, 0) * n_candidates += 1 */ - __pyx_t_5 = PyObject_Length(__pyx_cur_scope->__pyx_v_sequence); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(__pyx_cur_scope->__pyx_v_c_sequence + 0, __pyx_t_5 - 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_12 = PyBytes_AS_STRING(__pyx_t_1); - __pyx_t_13 = (__pyx_t_12 + PyBytes_GET_SIZE(__pyx_t_1)); - for (__pyx_t_14 = __pyx_t_12; __pyx_t_14 < __pyx_t_13; __pyx_t_14++) { - __pyx_t_7 = __pyx_t_14; - __pyx_cur_scope->__pyx_v_char = (__pyx_t_7[0]); + __pyx_t_5 = PyObject_Length(__pyx_cur_scope->__pyx_v_sequence); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __pyx_t_4 = __Pyx_PyBytes_FromStringAndSize(__pyx_cur_scope->__pyx_v_c_sequence + 0, __pyx_t_5 - 0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_14 = PyBytes_AS_STRING(__pyx_t_4); + __pyx_t_15 = (__pyx_t_14 + PyBytes_GET_SIZE(__pyx_t_4)); + for (__pyx_t_16 = __pyx_t_14; __pyx_t_16 < __pyx_t_15; __pyx_t_16++) { + __pyx_t_10 = __pyx_t_16; + __pyx_cur_scope->__pyx_v_char = (__pyx_t_10[0]); - /* "fuzzysearch/_generic_search.pyx":89 + /* "fuzzysearch/_generic_search.pyx":88 * have_realloced = False * for char in c_sequence[:len(sequence)]: * candidates[n_candidates] = GenericSearchCandidate(index, 0, 0, 0, 0, 0) # <<<<<<<<<<<<<< * n_candidates += 1 * */ - __pyx_t_15.start = __pyx_cur_scope->__pyx_v_index; - __pyx_t_15.subseq_index = 0; - __pyx_t_15.l_dist = 0; - __pyx_t_15.n_subs = 0; - __pyx_t_15.n_ins = 0; - __pyx_t_15.n_dels = 0; - (__pyx_cur_scope->__pyx_v_candidates[__pyx_cur_scope->__pyx_v_n_candidates]) = __pyx_t_15; + __pyx_t_17.start = __pyx_cur_scope->__pyx_v_index; + __pyx_t_17.subseq_index = 0; + __pyx_t_17.l_dist = 0; + __pyx_t_17.n_subs = 0; + __pyx_t_17.n_ins = 0; + __pyx_t_17.n_dels = 0; + (__pyx_cur_scope->__pyx_v_candidates[__pyx_cur_scope->__pyx_v_n_candidates]) = __pyx_t_17; - /* "fuzzysearch/_generic_search.pyx":90 + /* "fuzzysearch/_generic_search.pyx":89 * for char in c_sequence[:len(sequence)]: * candidates[n_candidates] = GenericSearchCandidate(index, 0, 0, 0, 0, 0) * n_candidates += 1 # <<<<<<<<<<<<<< @@ -1795,18 +1663,18 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener */ __pyx_cur_scope->__pyx_v_n_candidates = (__pyx_cur_scope->__pyx_v_n_candidates + 1); - /* "fuzzysearch/_generic_search.pyx":92 + /* "fuzzysearch/_generic_search.pyx":91 * n_candidates += 1 * * for n_cand in xrange(n_candidates): # <<<<<<<<<<<<<< * cand = candidates[n_cand] * */ - __pyx_t_16 = __pyx_cur_scope->__pyx_v_n_candidates; - for (__pyx_t_17 = 0; __pyx_t_17 < __pyx_t_16; __pyx_t_17+=1) { - __pyx_cur_scope->__pyx_v_n_cand = __pyx_t_17; + __pyx_t_13 = __pyx_cur_scope->__pyx_v_n_candidates; + for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_13; __pyx_t_11+=1) { + __pyx_cur_scope->__pyx_v_n_cand = __pyx_t_11; - /* "fuzzysearch/_generic_search.pyx":93 + /* "fuzzysearch/_generic_search.pyx":92 * * for n_cand in xrange(n_candidates): * cand = candidates[n_cand] # <<<<<<<<<<<<<< @@ -1815,75 +1683,55 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener */ __pyx_cur_scope->__pyx_v_cand = (__pyx_cur_scope->__pyx_v_candidates[__pyx_cur_scope->__pyx_v_n_cand]); - /* "fuzzysearch/_generic_search.pyx":95 + /* "fuzzysearch/_generic_search.pyx":94 * cand = candidates[n_cand] * * if n_new_candidates + 4 > alloc_size: # <<<<<<<<<<<<<< - * alloc_size += alloc_size // 2 + * alloc_size *= 2 * _tmp = realloc(new_candidates, alloc_size * sizeof(GenericSearchCandidate)) */ - __pyx_t_4 = __Pyx_PyInt_From_long((__pyx_cur_scope->__pyx_v_n_new_candidates + 4)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_18 = PyObject_RichCompare(__pyx_t_4, __pyx_cur_scope->__pyx_v_alloc_size, Py_GT); __Pyx_XGOTREF(__pyx_t_18); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_18); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - if (__pyx_t_6) { + __pyx_t_3 = (((__pyx_cur_scope->__pyx_v_n_new_candidates + 4) > __pyx_cur_scope->__pyx_v_alloc_size) != 0); + if (__pyx_t_3) { - /* "fuzzysearch/_generic_search.pyx":96 + /* "fuzzysearch/_generic_search.pyx":95 * * if n_new_candidates + 4 > alloc_size: - * alloc_size += alloc_size // 2 # <<<<<<<<<<<<<< + * alloc_size *= 2 # <<<<<<<<<<<<<< * _tmp = realloc(new_candidates, alloc_size * sizeof(GenericSearchCandidate)) * if _tmp is NULL: */ - __pyx_t_18 = PyNumber_FloorDivide(__pyx_cur_scope->__pyx_v_alloc_size, __pyx_int_2); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_cur_scope->__pyx_v_alloc_size, __pyx_t_18); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_alloc_size); - __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_alloc_size, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; + __pyx_cur_scope->__pyx_v_alloc_size = (__pyx_cur_scope->__pyx_v_alloc_size * 2); - /* "fuzzysearch/_generic_search.pyx":97 + /* "fuzzysearch/_generic_search.pyx":96 * if n_new_candidates + 4 > alloc_size: - * alloc_size += alloc_size // 2 + * alloc_size *= 2 * _tmp = realloc(new_candidates, alloc_size * sizeof(GenericSearchCandidate)) # <<<<<<<<<<<<<< * if _tmp is NULL: * raise MemoryError() */ - __pyx_t_4 = __Pyx_PyInt_FromSize_t((sizeof(struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate))); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_18 = PyNumber_Multiply(__pyx_cur_scope->__pyx_v_alloc_size, __pyx_t_4); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_18); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_11 = __Pyx_PyInt_As_size_t(__pyx_t_18); if (unlikely((__pyx_t_11 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __pyx_cur_scope->__pyx_v__tmp = ((struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate *)realloc(__pyx_cur_scope->__pyx_v_new_candidates, __pyx_t_11)); + __pyx_cur_scope->__pyx_v__tmp = ((struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate *)realloc(__pyx_cur_scope->__pyx_v_new_candidates, (__pyx_cur_scope->__pyx_v_alloc_size * (sizeof(struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate))))); - /* "fuzzysearch/_generic_search.pyx":98 - * alloc_size += alloc_size // 2 + /* "fuzzysearch/_generic_search.pyx":97 + * alloc_size *= 2 * _tmp = realloc(new_candidates, alloc_size * sizeof(GenericSearchCandidate)) * if _tmp is NULL: # <<<<<<<<<<<<<< * raise MemoryError() * new_candidates = _tmp */ - __pyx_t_6 = ((__pyx_cur_scope->__pyx_v__tmp == NULL) != 0); - if (__pyx_t_6) { + __pyx_t_3 = ((__pyx_cur_scope->__pyx_v__tmp == NULL) != 0); + if (__pyx_t_3) { - /* "fuzzysearch/_generic_search.pyx":99 + /* "fuzzysearch/_generic_search.pyx":98 * _tmp = realloc(new_candidates, alloc_size * sizeof(GenericSearchCandidate)) * if _tmp is NULL: * raise MemoryError() # <<<<<<<<<<<<<< * new_candidates = _tmp * have_realloced = True */ - PyErr_NoMemory(); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + PyErr_NoMemory(); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L10_error;} } - /* "fuzzysearch/_generic_search.pyx":100 + /* "fuzzysearch/_generic_search.pyx":99 * if _tmp is NULL: * raise MemoryError() * new_candidates = _tmp # <<<<<<<<<<<<<< @@ -1892,7 +1740,7 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener */ __pyx_cur_scope->__pyx_v_new_candidates = __pyx_cur_scope->__pyx_v__tmp; - /* "fuzzysearch/_generic_search.pyx":101 + /* "fuzzysearch/_generic_search.pyx":100 * raise MemoryError() * new_candidates = _tmp * have_realloced = True # <<<<<<<<<<<<<< @@ -1900,130 +1748,130 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener * # if this sequence char is the candidate's next expected char */ __pyx_cur_scope->__pyx_v_have_realloced = 1; - goto __pyx_L17; + goto __pyx_L16; } - __pyx_L17:; + __pyx_L16:; - /* "fuzzysearch/_generic_search.pyx":104 + /* "fuzzysearch/_generic_search.pyx":103 * * # if this sequence char is the candidate's next expected char * if char == c_subsequence[cand.subseq_index]: # <<<<<<<<<<<<<< * # if reached the end of the subsequence, return a match * if cand.subseq_index == _subseq_len_minus_one: */ - __pyx_t_6 = ((__pyx_cur_scope->__pyx_v_char == (__pyx_cur_scope->__pyx_v_c_subsequence[__pyx_cur_scope->__pyx_v_cand.subseq_index])) != 0); - if (__pyx_t_6) { + __pyx_t_3 = ((__pyx_cur_scope->__pyx_v_char == (__pyx_cur_scope->__pyx_v_c_subsequence[__pyx_cur_scope->__pyx_v_cand.subseq_index])) != 0); + if (__pyx_t_3) { - /* "fuzzysearch/_generic_search.pyx":106 + /* "fuzzysearch/_generic_search.pyx":105 * if char == c_subsequence[cand.subseq_index]: * # if reached the end of the subsequence, return a match * if cand.subseq_index == _subseq_len_minus_one: # <<<<<<<<<<<<<< * yield Match(cand.start, index + 1, cand.l_dist) * # otherwise, update the candidate's subseq_index and keep it */ - __pyx_t_6 = ((__pyx_cur_scope->__pyx_v_cand.subseq_index == __pyx_cur_scope->__pyx_v__subseq_len_minus_one) != 0); - if (__pyx_t_6) { + __pyx_t_3 = ((__pyx_cur_scope->__pyx_v_cand.subseq_index == __pyx_cur_scope->__pyx_v__subseq_len_minus_one) != 0); + if (__pyx_t_3) { - /* "fuzzysearch/_generic_search.pyx":107 + /* "fuzzysearch/_generic_search.pyx":106 * # if reached the end of the subsequence, return a match * if cand.subseq_index == _subseq_len_minus_one: * yield Match(cand.start, index + 1, cand.l_dist) # <<<<<<<<<<<<<< * # otherwise, update the candidate's subseq_index and keep it * else: */ - __pyx_t_18 = __Pyx_GetModuleGlobalName(__pyx_n_s_Match); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_Match); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.start); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_8 = __Pyx_PyInt_FromSize_t((__pyx_cur_scope->__pyx_v_index + 1)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.l_dist); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L10_error;} __Pyx_GOTREF(__pyx_t_18); - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.start); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_19 = __Pyx_PyInt_From_long((__pyx_cur_scope->__pyx_v_index + 1)); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + __pyx_t_19 = PyTuple_New(3); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L10_error;} __Pyx_GOTREF(__pyx_t_19); - __pyx_t_20 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.l_dist); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_20); - __pyx_t_21 = PyTuple_New(3); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_21); - PyTuple_SET_ITEM(__pyx_t_21, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_21, 1, __pyx_t_19); - __Pyx_GIVEREF(__pyx_t_19); - PyTuple_SET_ITEM(__pyx_t_21, 2, __pyx_t_20); - __Pyx_GIVEREF(__pyx_t_20); - __pyx_t_4 = 0; - __pyx_t_19 = 0; - __pyx_t_20 = 0; - __pyx_t_20 = __Pyx_PyObject_Call(__pyx_t_18, __pyx_t_21, NULL); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - __pyx_r = __pyx_t_20; - __pyx_t_20 = 0; - __Pyx_XGIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_7; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_12; + PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_9); + __Pyx_GIVEREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_19, 1, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_19, 2, __pyx_t_18); + __Pyx_GIVEREF(__pyx_t_18); + __pyx_t_9 = 0; + __pyx_t_8 = 0; + __pyx_t_18 = 0; + __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_19, NULL); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_18); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __pyx_r = __pyx_t_18; + __pyx_t_18 = 0; + __Pyx_XGIVEREF(__pyx_t_4); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_4; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_10; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_11; __pyx_cur_scope->__pyx_t_3 = __pyx_t_13; __pyx_cur_scope->__pyx_t_4 = __pyx_t_14; - __pyx_cur_scope->__pyx_t_5 = __pyx_t_16; - __pyx_cur_scope->__pyx_t_6 = __pyx_t_17; + __pyx_cur_scope->__pyx_t_5 = __pyx_t_15; + __pyx_cur_scope->__pyx_t_6 = __pyx_t_16; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); /* return from generator, yielding value */ __pyx_generator->resume_label = 1; return __pyx_r; - __pyx_L21_resume_from_yield:; - __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_L20_resume_from_yield:; + __pyx_t_4 = __pyx_cur_scope->__pyx_t_0; __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_1); - __pyx_t_7 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_12 = __pyx_cur_scope->__pyx_t_2; + __Pyx_XGOTREF(__pyx_t_4); + __pyx_t_10 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_11 = __pyx_cur_scope->__pyx_t_2; __pyx_t_13 = __pyx_cur_scope->__pyx_t_3; __pyx_t_14 = __pyx_cur_scope->__pyx_t_4; - __pyx_t_16 = __pyx_cur_scope->__pyx_t_5; - __pyx_t_17 = __pyx_cur_scope->__pyx_t_6; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - goto __pyx_L20; + __pyx_t_15 = __pyx_cur_scope->__pyx_t_5; + __pyx_t_16 = __pyx_cur_scope->__pyx_t_6; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + goto __pyx_L19; } /*else*/ { - /* "fuzzysearch/_generic_search.pyx":111 + /* "fuzzysearch/_generic_search.pyx":110 * else: * new_candidates[n_new_candidates] = GenericSearchCandidate( * cand.start, cand.subseq_index + 1, # <<<<<<<<<<<<<< * cand.l_dist, cand.n_subs, * cand.n_ins, cand.n_dels, */ - __pyx_t_15.start = __pyx_cur_scope->__pyx_v_cand.start; - __pyx_t_15.subseq_index = (__pyx_cur_scope->__pyx_v_cand.subseq_index + 1); + __pyx_t_17.start = __pyx_cur_scope->__pyx_v_cand.start; + __pyx_t_17.subseq_index = (__pyx_cur_scope->__pyx_v_cand.subseq_index + 1); - /* "fuzzysearch/_generic_search.pyx":112 + /* "fuzzysearch/_generic_search.pyx":111 * new_candidates[n_new_candidates] = GenericSearchCandidate( * cand.start, cand.subseq_index + 1, * cand.l_dist, cand.n_subs, # <<<<<<<<<<<<<< * cand.n_ins, cand.n_dels, * ) */ - __pyx_t_15.l_dist = __pyx_cur_scope->__pyx_v_cand.l_dist; - __pyx_t_15.n_subs = __pyx_cur_scope->__pyx_v_cand.n_subs; + __pyx_t_17.l_dist = __pyx_cur_scope->__pyx_v_cand.l_dist; + __pyx_t_17.n_subs = __pyx_cur_scope->__pyx_v_cand.n_subs; - /* "fuzzysearch/_generic_search.pyx":113 + /* "fuzzysearch/_generic_search.pyx":112 * cand.start, cand.subseq_index + 1, * cand.l_dist, cand.n_subs, * cand.n_ins, cand.n_dels, # <<<<<<<<<<<<<< * ) * n_new_candidates += 1 */ - __pyx_t_15.n_ins = __pyx_cur_scope->__pyx_v_cand.n_ins; - __pyx_t_15.n_dels = __pyx_cur_scope->__pyx_v_cand.n_dels; + __pyx_t_17.n_ins = __pyx_cur_scope->__pyx_v_cand.n_ins; + __pyx_t_17.n_dels = __pyx_cur_scope->__pyx_v_cand.n_dels; - /* "fuzzysearch/_generic_search.pyx":110 + /* "fuzzysearch/_generic_search.pyx":109 * # otherwise, update the candidate's subseq_index and keep it * else: * new_candidates[n_new_candidates] = GenericSearchCandidate( # <<<<<<<<<<<<<< * cand.start, cand.subseq_index + 1, * cand.l_dist, cand.n_subs, */ - (__pyx_cur_scope->__pyx_v_new_candidates[__pyx_cur_scope->__pyx_v_n_new_candidates]) = __pyx_t_15; + (__pyx_cur_scope->__pyx_v_new_candidates[__pyx_cur_scope->__pyx_v_n_new_candidates]) = __pyx_t_17; - /* "fuzzysearch/_generic_search.pyx":115 + /* "fuzzysearch/_generic_search.pyx":114 * cand.n_ins, cand.n_dels, * ) * n_new_candidates += 1 # <<<<<<<<<<<<<< @@ -2032,91 +1880,81 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener */ __pyx_cur_scope->__pyx_v_n_new_candidates = (__pyx_cur_scope->__pyx_v_n_new_candidates + 1); } - __pyx_L20:; - goto __pyx_L19; + __pyx_L19:; + goto __pyx_L18; } /*else*/ { - /* "fuzzysearch/_generic_search.pyx":122 + /* "fuzzysearch/_generic_search.pyx":121 * # unless this candidate has already skipped the maximum allowed * # number of characters * if cand.l_dist == c_max_l_dist: # <<<<<<<<<<<<<< * continue * */ - __pyx_t_20 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.l_dist); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_20); - __pyx_t_21 = PyObject_RichCompare(__pyx_t_20, __pyx_cur_scope->__pyx_v_c_max_l_dist, Py_EQ); __Pyx_XGOTREF(__pyx_t_21); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_21); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - if (__pyx_t_6) { + __pyx_t_3 = ((__pyx_cur_scope->__pyx_v_cand.l_dist == __pyx_cur_scope->__pyx_v_c_max_l_dist) != 0); + if (__pyx_t_3) { - /* "fuzzysearch/_generic_search.pyx":123 + /* "fuzzysearch/_generic_search.pyx":122 * # number of characters * if cand.l_dist == c_max_l_dist: * continue # <<<<<<<<<<<<<< * * if cand.n_ins < c_max_insertions: */ - goto __pyx_L15_continue; + goto __pyx_L14_continue; } - /* "fuzzysearch/_generic_search.pyx":125 + /* "fuzzysearch/_generic_search.pyx":124 * continue * * if cand.n_ins < c_max_insertions: # <<<<<<<<<<<<<< * # add a candidate skipping a sequence char * new_candidates[n_new_candidates] = GenericSearchCandidate( */ - __pyx_t_21 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.n_ins); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_21); - __pyx_t_20 = PyObject_RichCompare(__pyx_t_21, __pyx_cur_scope->__pyx_v_c_max_insertions, Py_LT); __Pyx_XGOTREF(__pyx_t_20); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_20); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - if (__pyx_t_6) { + __pyx_t_3 = ((__pyx_cur_scope->__pyx_v_cand.n_ins < __pyx_cur_scope->__pyx_v_c_max_insertions) != 0); + if (__pyx_t_3) { - /* "fuzzysearch/_generic_search.pyx":128 + /* "fuzzysearch/_generic_search.pyx":127 * # add a candidate skipping a sequence char * new_candidates[n_new_candidates] = GenericSearchCandidate( * cand.start, cand.subseq_index, # <<<<<<<<<<<<<< * cand.l_dist + 1, cand.n_subs, * cand.n_ins + 1, cand.n_dels, */ - __pyx_t_15.start = __pyx_cur_scope->__pyx_v_cand.start; - __pyx_t_15.subseq_index = __pyx_cur_scope->__pyx_v_cand.subseq_index; + __pyx_t_17.start = __pyx_cur_scope->__pyx_v_cand.start; + __pyx_t_17.subseq_index = __pyx_cur_scope->__pyx_v_cand.subseq_index; - /* "fuzzysearch/_generic_search.pyx":129 + /* "fuzzysearch/_generic_search.pyx":128 * new_candidates[n_new_candidates] = GenericSearchCandidate( * cand.start, cand.subseq_index, * cand.l_dist + 1, cand.n_subs, # <<<<<<<<<<<<<< * cand.n_ins + 1, cand.n_dels, * ) */ - __pyx_t_15.l_dist = (__pyx_cur_scope->__pyx_v_cand.l_dist + 1); - __pyx_t_15.n_subs = __pyx_cur_scope->__pyx_v_cand.n_subs; + __pyx_t_17.l_dist = (__pyx_cur_scope->__pyx_v_cand.l_dist + 1); + __pyx_t_17.n_subs = __pyx_cur_scope->__pyx_v_cand.n_subs; - /* "fuzzysearch/_generic_search.pyx":130 + /* "fuzzysearch/_generic_search.pyx":129 * cand.start, cand.subseq_index, * cand.l_dist + 1, cand.n_subs, * cand.n_ins + 1, cand.n_dels, # <<<<<<<<<<<<<< * ) * n_new_candidates += 1 */ - __pyx_t_15.n_ins = (__pyx_cur_scope->__pyx_v_cand.n_ins + 1); - __pyx_t_15.n_dels = __pyx_cur_scope->__pyx_v_cand.n_dels; + __pyx_t_17.n_ins = (__pyx_cur_scope->__pyx_v_cand.n_ins + 1); + __pyx_t_17.n_dels = __pyx_cur_scope->__pyx_v_cand.n_dels; - /* "fuzzysearch/_generic_search.pyx":127 + /* "fuzzysearch/_generic_search.pyx":126 * if cand.n_ins < c_max_insertions: * # add a candidate skipping a sequence char * new_candidates[n_new_candidates] = GenericSearchCandidate( # <<<<<<<<<<<<<< * cand.start, cand.subseq_index, * cand.l_dist + 1, cand.n_subs, */ - (__pyx_cur_scope->__pyx_v_new_candidates[__pyx_cur_scope->__pyx_v_n_new_candidates]) = __pyx_t_15; + (__pyx_cur_scope->__pyx_v_new_candidates[__pyx_cur_scope->__pyx_v_n_new_candidates]) = __pyx_t_17; - /* "fuzzysearch/_generic_search.pyx":132 + /* "fuzzysearch/_generic_search.pyx":131 * cand.n_ins + 1, cand.n_dels, * ) * n_new_candidates += 1 # <<<<<<<<<<<<<< @@ -2124,75 +1962,70 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener * if cand.subseq_index + 1 < _subseq_len: */ __pyx_cur_scope->__pyx_v_n_new_candidates = (__pyx_cur_scope->__pyx_v_n_new_candidates + 1); - goto __pyx_L23; + goto __pyx_L22; } - __pyx_L23:; + __pyx_L22:; - /* "fuzzysearch/_generic_search.pyx":134 + /* "fuzzysearch/_generic_search.pyx":133 * n_new_candidates += 1 * * if cand.subseq_index + 1 < _subseq_len: # <<<<<<<<<<<<<< * if cand.n_subs < c_max_substitutions: * # add a candidate skipping both a sequence char and a */ - __pyx_t_6 = (((__pyx_cur_scope->__pyx_v_cand.subseq_index + 1) < __pyx_cur_scope->__pyx_v__subseq_len) != 0); - if (__pyx_t_6) { + __pyx_t_3 = (((__pyx_cur_scope->__pyx_v_cand.subseq_index + 1) < __pyx_cur_scope->__pyx_v__subseq_len) != 0); + if (__pyx_t_3) { - /* "fuzzysearch/_generic_search.pyx":135 + /* "fuzzysearch/_generic_search.pyx":134 * * if cand.subseq_index + 1 < _subseq_len: * if cand.n_subs < c_max_substitutions: # <<<<<<<<<<<<<< * # add a candidate skipping both a sequence char and a * # subsequence char */ - __pyx_t_20 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.n_subs); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_20); - __pyx_t_21 = PyObject_RichCompare(__pyx_t_20, __pyx_cur_scope->__pyx_v_c_max_substitutions, Py_LT); __Pyx_XGOTREF(__pyx_t_21); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_21); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - if (__pyx_t_6) { + __pyx_t_3 = ((__pyx_cur_scope->__pyx_v_cand.n_subs < __pyx_cur_scope->__pyx_v_c_max_substitutions) != 0); + if (__pyx_t_3) { - /* "fuzzysearch/_generic_search.pyx":139 + /* "fuzzysearch/_generic_search.pyx":138 * # subsequence char * new_candidates[n_new_candidates] = GenericSearchCandidate( * cand.start, cand.subseq_index + 1, # <<<<<<<<<<<<<< * cand.l_dist + 1, cand.n_subs + 1, * cand.n_ins, cand.n_dels, */ - __pyx_t_15.start = __pyx_cur_scope->__pyx_v_cand.start; - __pyx_t_15.subseq_index = (__pyx_cur_scope->__pyx_v_cand.subseq_index + 1); + __pyx_t_17.start = __pyx_cur_scope->__pyx_v_cand.start; + __pyx_t_17.subseq_index = (__pyx_cur_scope->__pyx_v_cand.subseq_index + 1); - /* "fuzzysearch/_generic_search.pyx":140 + /* "fuzzysearch/_generic_search.pyx":139 * new_candidates[n_new_candidates] = GenericSearchCandidate( * cand.start, cand.subseq_index + 1, * cand.l_dist + 1, cand.n_subs + 1, # <<<<<<<<<<<<<< * cand.n_ins, cand.n_dels, * ) */ - __pyx_t_15.l_dist = (__pyx_cur_scope->__pyx_v_cand.l_dist + 1); - __pyx_t_15.n_subs = (__pyx_cur_scope->__pyx_v_cand.n_subs + 1); + __pyx_t_17.l_dist = (__pyx_cur_scope->__pyx_v_cand.l_dist + 1); + __pyx_t_17.n_subs = (__pyx_cur_scope->__pyx_v_cand.n_subs + 1); - /* "fuzzysearch/_generic_search.pyx":141 + /* "fuzzysearch/_generic_search.pyx":140 * cand.start, cand.subseq_index + 1, * cand.l_dist + 1, cand.n_subs + 1, * cand.n_ins, cand.n_dels, # <<<<<<<<<<<<<< * ) * n_new_candidates += 1 */ - __pyx_t_15.n_ins = __pyx_cur_scope->__pyx_v_cand.n_ins; - __pyx_t_15.n_dels = __pyx_cur_scope->__pyx_v_cand.n_dels; + __pyx_t_17.n_ins = __pyx_cur_scope->__pyx_v_cand.n_ins; + __pyx_t_17.n_dels = __pyx_cur_scope->__pyx_v_cand.n_dels; - /* "fuzzysearch/_generic_search.pyx":138 + /* "fuzzysearch/_generic_search.pyx":137 * # add a candidate skipping both a sequence char and a * # subsequence char * new_candidates[n_new_candidates] = GenericSearchCandidate( # <<<<<<<<<<<<<< * cand.start, cand.subseq_index + 1, * cand.l_dist + 1, cand.n_subs + 1, */ - (__pyx_cur_scope->__pyx_v_new_candidates[__pyx_cur_scope->__pyx_v_n_new_candidates]) = __pyx_t_15; + (__pyx_cur_scope->__pyx_v_new_candidates[__pyx_cur_scope->__pyx_v_n_new_candidates]) = __pyx_t_17; - /* "fuzzysearch/_generic_search.pyx":143 + /* "fuzzysearch/_generic_search.pyx":142 * cand.n_ins, cand.n_dels, * ) * n_new_candidates += 1 # <<<<<<<<<<<<<< @@ -2200,75 +2033,65 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener * # add a candidate skipping both a sequence char and a */ __pyx_cur_scope->__pyx_v_n_new_candidates = (__pyx_cur_scope->__pyx_v_n_new_candidates + 1); - goto __pyx_L25; + goto __pyx_L24; } - /* "fuzzysearch/_generic_search.pyx":144 + /* "fuzzysearch/_generic_search.pyx":143 * ) * n_new_candidates += 1 * elif cand.n_dels < c_max_deletions and cand.n_ins < c_max_insertions: # <<<<<<<<<<<<<< * # add a candidate skipping both a sequence char and a * # subsequence char */ - __pyx_t_21 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.n_dels); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_21); - __pyx_t_20 = PyObject_RichCompare(__pyx_t_21, __pyx_cur_scope->__pyx_v_c_max_deletions, Py_LT); __Pyx_XGOTREF(__pyx_t_20); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_20); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - if (__pyx_t_6) { - __pyx_t_20 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.n_ins); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_20); - __pyx_t_21 = PyObject_RichCompare(__pyx_t_20, __pyx_cur_scope->__pyx_v_c_max_insertions, Py_LT); __Pyx_XGOTREF(__pyx_t_21); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_21); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 144; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - __pyx_t_2 = __pyx_t_3; + __pyx_t_3 = ((__pyx_cur_scope->__pyx_v_cand.n_dels < __pyx_cur_scope->__pyx_v_c_max_deletions) != 0); + if (__pyx_t_3) { + __pyx_t_2 = ((__pyx_cur_scope->__pyx_v_cand.n_ins < __pyx_cur_scope->__pyx_v_c_max_insertions) != 0); + __pyx_t_20 = __pyx_t_2; } else { - __pyx_t_2 = __pyx_t_6; + __pyx_t_20 = __pyx_t_3; } - if (__pyx_t_2) { + if (__pyx_t_20) { - /* "fuzzysearch/_generic_search.pyx":148 + /* "fuzzysearch/_generic_search.pyx":147 * # subsequence char * new_candidates[n_new_candidates] = GenericSearchCandidate( * cand.start, cand.subseq_index + 1, # <<<<<<<<<<<<<< * cand.l_dist + 1, cand.n_subs, * cand.n_ins + 1, cand.n_dels + 1, */ - __pyx_t_15.start = __pyx_cur_scope->__pyx_v_cand.start; - __pyx_t_15.subseq_index = (__pyx_cur_scope->__pyx_v_cand.subseq_index + 1); + __pyx_t_17.start = __pyx_cur_scope->__pyx_v_cand.start; + __pyx_t_17.subseq_index = (__pyx_cur_scope->__pyx_v_cand.subseq_index + 1); - /* "fuzzysearch/_generic_search.pyx":149 + /* "fuzzysearch/_generic_search.pyx":148 * new_candidates[n_new_candidates] = GenericSearchCandidate( * cand.start, cand.subseq_index + 1, * cand.l_dist + 1, cand.n_subs, # <<<<<<<<<<<<<< * cand.n_ins + 1, cand.n_dels + 1, * ) */ - __pyx_t_15.l_dist = (__pyx_cur_scope->__pyx_v_cand.l_dist + 1); - __pyx_t_15.n_subs = __pyx_cur_scope->__pyx_v_cand.n_subs; + __pyx_t_17.l_dist = (__pyx_cur_scope->__pyx_v_cand.l_dist + 1); + __pyx_t_17.n_subs = __pyx_cur_scope->__pyx_v_cand.n_subs; - /* "fuzzysearch/_generic_search.pyx":150 + /* "fuzzysearch/_generic_search.pyx":149 * cand.start, cand.subseq_index + 1, * cand.l_dist + 1, cand.n_subs, * cand.n_ins + 1, cand.n_dels + 1, # <<<<<<<<<<<<<< * ) * n_new_candidates += 1 */ - __pyx_t_15.n_ins = (__pyx_cur_scope->__pyx_v_cand.n_ins + 1); - __pyx_t_15.n_dels = (__pyx_cur_scope->__pyx_v_cand.n_dels + 1); + __pyx_t_17.n_ins = (__pyx_cur_scope->__pyx_v_cand.n_ins + 1); + __pyx_t_17.n_dels = (__pyx_cur_scope->__pyx_v_cand.n_dels + 1); - /* "fuzzysearch/_generic_search.pyx":147 + /* "fuzzysearch/_generic_search.pyx":146 * # add a candidate skipping both a sequence char and a * # subsequence char * new_candidates[n_new_candidates] = GenericSearchCandidate( # <<<<<<<<<<<<<< * cand.start, cand.subseq_index + 1, * cand.l_dist + 1, cand.n_subs, */ - (__pyx_cur_scope->__pyx_v_new_candidates[__pyx_cur_scope->__pyx_v_n_new_candidates]) = __pyx_t_15; + (__pyx_cur_scope->__pyx_v_new_candidates[__pyx_cur_scope->__pyx_v_n_new_candidates]) = __pyx_t_17; - /* "fuzzysearch/_generic_search.pyx":152 + /* "fuzzysearch/_generic_search.pyx":151 * cand.n_ins + 1, cand.n_dels + 1, * ) * n_new_candidates += 1 # <<<<<<<<<<<<<< @@ -2276,534 +2099,487 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener * # cand.subseq_index == _subseq_len - 1 */ __pyx_cur_scope->__pyx_v_n_new_candidates = (__pyx_cur_scope->__pyx_v_n_new_candidates + 1); - goto __pyx_L25; + goto __pyx_L24; } - __pyx_L25:; - goto __pyx_L24; + __pyx_L24:; + goto __pyx_L23; } /*else*/ { - /* "fuzzysearch/_generic_search.pyx":156 + /* "fuzzysearch/_generic_search.pyx":155 * # cand.subseq_index == _subseq_len - 1 * if ( * cand.n_subs < c_max_substitutions or # <<<<<<<<<<<<<< * ( * cand.n_dels < c_max_deletions and */ - __pyx_t_21 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.n_subs); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_21); - __pyx_t_20 = PyObject_RichCompare(__pyx_t_21, __pyx_cur_scope->__pyx_v_c_max_substitutions, Py_LT); __Pyx_XGOTREF(__pyx_t_20); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_20); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - if (!__pyx_t_2) { + __pyx_t_20 = ((__pyx_cur_scope->__pyx_v_cand.n_subs < __pyx_cur_scope->__pyx_v_c_max_substitutions) != 0); + if (!__pyx_t_20) { - /* "fuzzysearch/_generic_search.pyx":158 + /* "fuzzysearch/_generic_search.pyx":157 * cand.n_subs < c_max_substitutions or * ( * cand.n_dels < c_max_deletions and # <<<<<<<<<<<<<< * cand.n_ins < c_max_insertions * ) */ - __pyx_t_20 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.n_dels); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_20); - __pyx_t_21 = PyObject_RichCompare(__pyx_t_20, __pyx_cur_scope->__pyx_v_c_max_deletions, Py_LT); __Pyx_XGOTREF(__pyx_t_21); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_21); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 158; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - if (__pyx_t_6) { + __pyx_t_3 = ((__pyx_cur_scope->__pyx_v_cand.n_dels < __pyx_cur_scope->__pyx_v_c_max_deletions) != 0); + if (__pyx_t_3) { - /* "fuzzysearch/_generic_search.pyx":159 + /* "fuzzysearch/_generic_search.pyx":158 * ( * cand.n_dels < c_max_deletions and * cand.n_ins < c_max_insertions # <<<<<<<<<<<<<< * ) * ): */ - __pyx_t_21 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.n_ins); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_21); - - /* "fuzzysearch/_generic_search.pyx":160 - * cand.n_dels < c_max_deletions and - * cand.n_ins < c_max_insertions - * ) # <<<<<<<<<<<<<< - * ): - * yield Match(cand.start, index + 1, cand.l_dist + 1) - */ - __pyx_t_20 = PyObject_RichCompare(__pyx_t_21, __pyx_cur_scope->__pyx_v_c_max_insertions, Py_LT); __Pyx_XGOTREF(__pyx_t_20); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - - /* "fuzzysearch/_generic_search.pyx":159 - * ( - * cand.n_dels < c_max_deletions and - * cand.n_ins < c_max_insertions # <<<<<<<<<<<<<< - * ) - * ): - */ - __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_20); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 159; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __pyx_t_22 = __pyx_t_3; + __pyx_t_2 = ((__pyx_cur_scope->__pyx_v_cand.n_ins < __pyx_cur_scope->__pyx_v_c_max_insertions) != 0); + __pyx_t_21 = __pyx_t_2; } else { - __pyx_t_22 = __pyx_t_6; + __pyx_t_21 = __pyx_t_3; } - __pyx_t_6 = __pyx_t_22; + __pyx_t_3 = __pyx_t_21; } else { - __pyx_t_6 = __pyx_t_2; + __pyx_t_3 = __pyx_t_20; } - if (__pyx_t_6) { + if (__pyx_t_3) { - /* "fuzzysearch/_generic_search.pyx":162 + /* "fuzzysearch/_generic_search.pyx":161 * ) * ): * yield Match(cand.start, index + 1, cand.l_dist + 1) # <<<<<<<<<<<<<< * * # try skipping subsequence chars */ - __pyx_t_20 = __Pyx_GetModuleGlobalName(__pyx_n_s_Match); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_20); - __pyx_t_21 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.start); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_21); - __pyx_t_18 = __Pyx_PyInt_From_long((__pyx_cur_scope->__pyx_v_index + 1)); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + __pyx_t_18 = __Pyx_GetModuleGlobalName(__pyx_n_s_Match); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L10_error;} __Pyx_GOTREF(__pyx_t_18); - __pyx_t_19 = __Pyx_PyInt_From_long((__pyx_cur_scope->__pyx_v_cand.l_dist + 1)); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + __pyx_t_19 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.start); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L10_error;} __Pyx_GOTREF(__pyx_t_19); - __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_21); - __Pyx_GIVEREF(__pyx_t_21); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_18); - __Pyx_GIVEREF(__pyx_t_18); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_19); + __pyx_t_1 = __Pyx_PyInt_FromSize_t((__pyx_cur_scope->__pyx_v_index + 1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = __Pyx_PyInt_From_long((__pyx_cur_scope->__pyx_v_cand.l_dist + 1)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_9); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_19); __Pyx_GIVEREF(__pyx_t_19); - __pyx_t_21 = 0; - __pyx_t_18 = 0; + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); __pyx_t_19 = 0; - __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_t_4, NULL); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_19); - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_r = __pyx_t_19; - __pyx_t_19 = 0; - __Pyx_XGIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_7; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_12; + __pyx_t_1 = 0; + __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_18, __pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_r = __pyx_t_8; + __pyx_t_8 = 0; + __Pyx_XGIVEREF(__pyx_t_4); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_4; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_10; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_11; __pyx_cur_scope->__pyx_t_3 = __pyx_t_13; __pyx_cur_scope->__pyx_t_4 = __pyx_t_14; - __pyx_cur_scope->__pyx_t_5 = __pyx_t_16; - __pyx_cur_scope->__pyx_t_6 = __pyx_t_17; + __pyx_cur_scope->__pyx_t_5 = __pyx_t_15; + __pyx_cur_scope->__pyx_t_6 = __pyx_t_16; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); /* return from generator, yielding value */ __pyx_generator->resume_label = 2; return __pyx_r; - __pyx_L27_resume_from_yield:; - __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_L26_resume_from_yield:; + __pyx_t_4 = __pyx_cur_scope->__pyx_t_0; __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_1); - __pyx_t_7 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_12 = __pyx_cur_scope->__pyx_t_2; + __Pyx_XGOTREF(__pyx_t_4); + __pyx_t_10 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_11 = __pyx_cur_scope->__pyx_t_2; __pyx_t_13 = __pyx_cur_scope->__pyx_t_3; __pyx_t_14 = __pyx_cur_scope->__pyx_t_4; - __pyx_t_16 = __pyx_cur_scope->__pyx_t_5; - __pyx_t_17 = __pyx_cur_scope->__pyx_t_6; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - goto __pyx_L26; + __pyx_t_15 = __pyx_cur_scope->__pyx_t_5; + __pyx_t_16 = __pyx_cur_scope->__pyx_t_6; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 161; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + goto __pyx_L25; } - __pyx_L26:; + __pyx_L25:; } - __pyx_L24:; + __pyx_L23:; - /* "fuzzysearch/_generic_search.pyx":165 + /* "fuzzysearch/_generic_search.pyx":164 * * # try skipping subsequence chars * for n_skipped in xrange(1, min(c_max_deletions - cand.n_dels, c_max_l_dist - cand.l_dist) + 1): # <<<<<<<<<<<<<< * # if skipping n_dels sub-sequence chars reaches the end * # of the sub-sequence, yield a match */ - __pyx_t_19 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.l_dist); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_19); - __pyx_t_4 = PyNumber_Subtract(__pyx_cur_scope->__pyx_v_c_max_l_dist, __pyx_t_19); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __pyx_t_19 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.n_dels); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_19); - __pyx_t_20 = PyNumber_Subtract(__pyx_cur_scope->__pyx_v_c_max_deletions, __pyx_t_19); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __pyx_t_18 = PyObject_RichCompare(__pyx_t_4, __pyx_t_20, Py_LT); __Pyx_XGOTREF(__pyx_t_18); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_18); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - if (__pyx_t_6) { - __Pyx_INCREF(__pyx_t_4); - __pyx_t_19 = __pyx_t_4; + __pyx_t_6 = (__pyx_cur_scope->__pyx_v_c_max_l_dist - __pyx_cur_scope->__pyx_v_cand.l_dist); + __pyx_t_7 = (__pyx_cur_scope->__pyx_v_c_max_deletions - __pyx_cur_scope->__pyx_v_cand.n_dels); + if (((__pyx_t_6 < __pyx_t_7) != 0)) { + __pyx_t_22 = __pyx_t_6; } else { - __Pyx_INCREF(__pyx_t_20); - __pyx_t_19 = __pyx_t_20; + __pyx_t_22 = __pyx_t_7; } - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyNumber_Add(__pyx_t_19, __pyx_int_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __pyx_t_19 = PyTuple_New(2); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_19); + __pyx_t_8 = __Pyx_PyInt_From_long((__pyx_t_22 + 1)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_9); __Pyx_INCREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_int_1); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_int_1); __Pyx_GIVEREF(__pyx_int_1); - PyTuple_SET_ITEM(__pyx_t_19, 1, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_xrange, __pyx_t_19, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - if (PyList_CheckExact(__pyx_t_4) || PyTuple_CheckExact(__pyx_t_4)) { - __pyx_t_19 = __pyx_t_4; __Pyx_INCREF(__pyx_t_19); __pyx_t_5 = 0; + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_xrange, __pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PyList_CheckExact(__pyx_t_8) || PyTuple_CheckExact(__pyx_t_8)) { + __pyx_t_9 = __pyx_t_8; __Pyx_INCREF(__pyx_t_9); __pyx_t_5 = 0; __pyx_t_23 = NULL; } else { - __pyx_t_5 = -1; __pyx_t_19 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_19); - __pyx_t_23 = Py_TYPE(__pyx_t_19)->tp_iternext; + __pyx_t_5 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_23 = Py_TYPE(__pyx_t_9)->tp_iternext; } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; for (;;) { - if (!__pyx_t_23 && PyList_CheckExact(__pyx_t_19)) { - if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_19)) break; + if (!__pyx_t_23 && PyList_CheckExact(__pyx_t_9)) { + if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_9)) break; #if CYTHON_COMPILING_IN_CPYTHON - __pyx_t_4 = PyList_GET_ITEM(__pyx_t_19, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + __pyx_t_8 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_5); __Pyx_INCREF(__pyx_t_8); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L10_error;} #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_19, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + __pyx_t_8 = PySequence_ITEM(__pyx_t_9, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L10_error;} #endif - } else if (!__pyx_t_23 && PyTuple_CheckExact(__pyx_t_19)) { - if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_19)) break; + } else if (!__pyx_t_23 && PyTuple_CheckExact(__pyx_t_9)) { + if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_9)) break; #if CYTHON_COMPILING_IN_CPYTHON - __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_19, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_5); __Pyx_INCREF(__pyx_t_8); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L10_error;} #else - __pyx_t_4 = PySequence_ITEM(__pyx_t_19, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + __pyx_t_8 = PySequence_ITEM(__pyx_t_9, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L10_error;} #endif } else { - __pyx_t_4 = __pyx_t_23(__pyx_t_19); - if (unlikely(!__pyx_t_4)) { + __pyx_t_8 = __pyx_t_23(__pyx_t_9); + if (unlikely(!__pyx_t_8)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L10_error;} } break; } - __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_8); } __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_n_skipped); - __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_n_skipped, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_t_4 = 0; + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_n_skipped, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_t_8 = 0; - /* "fuzzysearch/_generic_search.pyx":168 + /* "fuzzysearch/_generic_search.pyx":167 * # if skipping n_dels sub-sequence chars reaches the end * # of the sub-sequence, yield a match * if cand.subseq_index + n_skipped == _subseq_len: # <<<<<<<<<<<<<< * yield Match(cand.start, index + 1, * cand.l_dist + n_skipped) */ - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.subseq_index); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_20 = PyNumber_Add(__pyx_t_4, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v__subseq_len); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_18 = PyObject_RichCompare(__pyx_t_20, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_18); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_18); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.subseq_index); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_18 = PyNumber_Add(__pyx_t_8, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_18); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyInt_FromSize_t(__pyx_cur_scope->__pyx_v__subseq_len); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = PyObject_RichCompare(__pyx_t_18, __pyx_t_8, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L10_error;} __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - if (__pyx_t_6) { + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 167; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_3) { - /* "fuzzysearch/_generic_search.pyx":169 + /* "fuzzysearch/_generic_search.pyx":168 * # of the sub-sequence, yield a match * if cand.subseq_index + n_skipped == _subseq_len: * yield Match(cand.start, index + 1, # <<<<<<<<<<<<<< * cand.l_dist + n_skipped) * break */ - __pyx_t_18 = __Pyx_GetModuleGlobalName(__pyx_n_s_Match); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_Match); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.start); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_18 = __Pyx_PyInt_FromSize_t((__pyx_cur_scope->__pyx_v_index + 1)); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L10_error;} __Pyx_GOTREF(__pyx_t_18); - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.start); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_20 = __Pyx_PyInt_From_long((__pyx_cur_scope->__pyx_v_index + 1)); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_20); - /* "fuzzysearch/_generic_search.pyx":170 + /* "fuzzysearch/_generic_search.pyx":169 * if cand.subseq_index + n_skipped == _subseq_len: * yield Match(cand.start, index + 1, * cand.l_dist + n_skipped) # <<<<<<<<<<<<<< * break * # otherwise, if skipping n_skipped sub-sequence chars */ - __pyx_t_21 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.l_dist); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_21); - __pyx_t_24 = PyNumber_Add(__pyx_t_21, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 170; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + __pyx_t_19 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.l_dist); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_24 = PyNumber_Add(__pyx_t_19, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L10_error;} __Pyx_GOTREF(__pyx_t_24); - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - /* "fuzzysearch/_generic_search.pyx":169 + /* "fuzzysearch/_generic_search.pyx":168 * # of the sub-sequence, yield a match * if cand.subseq_index + n_skipped == _subseq_len: * yield Match(cand.start, index + 1, # <<<<<<<<<<<<<< * cand.l_dist + n_skipped) * break */ - __pyx_t_21 = PyTuple_New(3); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_21); - PyTuple_SET_ITEM(__pyx_t_21, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_21, 1, __pyx_t_20); - __Pyx_GIVEREF(__pyx_t_20); - PyTuple_SET_ITEM(__pyx_t_21, 2, __pyx_t_24); + __pyx_t_19 = PyTuple_New(3); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_19); + PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_19, 1, __pyx_t_18); + __Pyx_GIVEREF(__pyx_t_18); + PyTuple_SET_ITEM(__pyx_t_19, 2, __pyx_t_24); __Pyx_GIVEREF(__pyx_t_24); - __pyx_t_4 = 0; - __pyx_t_20 = 0; + __pyx_t_8 = 0; + __pyx_t_18 = 0; __pyx_t_24 = 0; - __pyx_t_24 = __Pyx_PyObject_Call(__pyx_t_18, __pyx_t_21, NULL); if (unlikely(!__pyx_t_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + __pyx_t_24 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_19, NULL); if (unlikely(!__pyx_t_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L10_error;} __Pyx_GOTREF(__pyx_t_24); - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; __pyx_r = __pyx_t_24; __pyx_t_24 = 0; - __Pyx_XGIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __Pyx_XGIVEREF(__pyx_t_4); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_4; __pyx_cur_scope->__pyx_t_7 = __pyx_t_5; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_7; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_12; + __Pyx_XGIVEREF(__pyx_t_9); + __pyx_cur_scope->__pyx_t_8 = __pyx_t_9; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_10; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_11; __pyx_cur_scope->__pyx_t_3 = __pyx_t_13; __pyx_cur_scope->__pyx_t_4 = __pyx_t_14; - __pyx_cur_scope->__pyx_t_5 = __pyx_t_16; - __pyx_cur_scope->__pyx_t_6 = __pyx_t_17; - __Pyx_XGIVEREF(__pyx_t_19); - __pyx_cur_scope->__pyx_t_8 = __pyx_t_19; + __pyx_cur_scope->__pyx_t_5 = __pyx_t_15; + __pyx_cur_scope->__pyx_t_6 = __pyx_t_16; __pyx_cur_scope->__pyx_t_9 = __pyx_t_23; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); /* return from generator, yielding value */ __pyx_generator->resume_label = 3; return __pyx_r; - __pyx_L31_resume_from_yield:; - __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_L30_resume_from_yield:; + __pyx_t_4 = __pyx_cur_scope->__pyx_t_0; __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_4); __pyx_t_5 = __pyx_cur_scope->__pyx_t_7; - __pyx_t_7 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_12 = __pyx_cur_scope->__pyx_t_2; + __pyx_t_9 = __pyx_cur_scope->__pyx_t_8; + __pyx_cur_scope->__pyx_t_8 = 0; + __Pyx_XGOTREF(__pyx_t_9); + __pyx_t_10 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_11 = __pyx_cur_scope->__pyx_t_2; __pyx_t_13 = __pyx_cur_scope->__pyx_t_3; __pyx_t_14 = __pyx_cur_scope->__pyx_t_4; - __pyx_t_16 = __pyx_cur_scope->__pyx_t_5; - __pyx_t_17 = __pyx_cur_scope->__pyx_t_6; - __pyx_t_19 = __pyx_cur_scope->__pyx_t_8; - __pyx_cur_scope->__pyx_t_8 = 0; - __Pyx_XGOTREF(__pyx_t_19); + __pyx_t_15 = __pyx_cur_scope->__pyx_t_5; + __pyx_t_16 = __pyx_cur_scope->__pyx_t_6; __pyx_t_23 = __pyx_cur_scope->__pyx_t_9; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L10_error;} - /* "fuzzysearch/_generic_search.pyx":171 + /* "fuzzysearch/_generic_search.pyx":170 * yield Match(cand.start, index + 1, * cand.l_dist + n_skipped) * break # <<<<<<<<<<<<<< * # otherwise, if skipping n_skipped sub-sequence chars * # reaches a sub-sequence char identical to this sequence */ - goto __pyx_L29_break; + goto __pyx_L28_break; } - /* "fuzzysearch/_generic_search.pyx":175 + /* "fuzzysearch/_generic_search.pyx":174 * # reaches a sub-sequence char identical to this sequence * # char ... * elif char == c_subsequence[cand.subseq_index + n_skipped]: # <<<<<<<<<<<<<< * # if this is the last char of the sub-sequence, yield * # a match */ - __pyx_t_24 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.subseq_index); if (unlikely(!__pyx_t_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + __pyx_t_24 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.subseq_index); if (unlikely(!__pyx_t_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L10_error;} __Pyx_GOTREF(__pyx_t_24); - __pyx_t_21 = PyNumber_Add(__pyx_t_24, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_21); + __pyx_t_19 = PyNumber_Add(__pyx_t_24, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_19); __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - __pyx_t_25 = __Pyx_PyIndex_AsSsize_t(__pyx_t_21); if (unlikely((__pyx_t_25 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - __pyx_t_6 = ((__pyx_cur_scope->__pyx_v_char == (__pyx_cur_scope->__pyx_v_c_subsequence[__pyx_t_25])) != 0); - if (__pyx_t_6) { + __pyx_t_25 = __Pyx_PyIndex_AsSsize_t(__pyx_t_19); if (unlikely((__pyx_t_25 == (Py_ssize_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __pyx_t_3 = ((__pyx_cur_scope->__pyx_v_char == (__pyx_cur_scope->__pyx_v_c_subsequence[__pyx_t_25])) != 0); + if (__pyx_t_3) { - /* "fuzzysearch/_generic_search.pyx":178 + /* "fuzzysearch/_generic_search.pyx":177 * # if this is the last char of the sub-sequence, yield * # a match * if cand.subseq_index + n_skipped + 1 == _subseq_len: # <<<<<<<<<<<<<< * yield Match(cand.start, index + 1, * cand.l_dist + n_skipped) */ - __pyx_t_21 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.subseq_index); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_21); - __pyx_t_24 = PyNumber_Add(__pyx_t_21, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + __pyx_t_19 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.subseq_index); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_24 = PyNumber_Add(__pyx_t_19, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L10_error;} __Pyx_GOTREF(__pyx_t_24); - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; - __pyx_t_21 = PyNumber_Add(__pyx_t_24, __pyx_int_1); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_21); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __pyx_t_19 = PyNumber_Add(__pyx_t_24, __pyx_int_1); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_19); __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - __pyx_t_24 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v__subseq_len); if (unlikely(!__pyx_t_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + __pyx_t_24 = __Pyx_PyInt_FromSize_t(__pyx_cur_scope->__pyx_v__subseq_len); if (unlikely(!__pyx_t_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L10_error;} __Pyx_GOTREF(__pyx_t_24); - __pyx_t_18 = PyObject_RichCompare(__pyx_t_21, __pyx_t_24, Py_EQ); __Pyx_XGOTREF(__pyx_t_18); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + __pyx_t_1 = PyObject_RichCompare(__pyx_t_19, __pyx_t_24, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_18); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - if (__pyx_t_6) { + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_3) { - /* "fuzzysearch/_generic_search.pyx":179 + /* "fuzzysearch/_generic_search.pyx":178 * # a match * if cand.subseq_index + n_skipped + 1 == _subseq_len: * yield Match(cand.start, index + 1, # <<<<<<<<<<<<<< * cand.l_dist + n_skipped) * # otherwise add a candidate skipping n_skipped */ - __pyx_t_18 = __Pyx_GetModuleGlobalName(__pyx_n_s_Match); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_18); - __pyx_t_24 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.start); if (unlikely(!__pyx_t_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_Match); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_24 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.start); if (unlikely(!__pyx_t_24)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L10_error;} __Pyx_GOTREF(__pyx_t_24); - __pyx_t_21 = __Pyx_PyInt_From_long((__pyx_cur_scope->__pyx_v_index + 1)); if (unlikely(!__pyx_t_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_21); + __pyx_t_19 = __Pyx_PyInt_FromSize_t((__pyx_cur_scope->__pyx_v_index + 1)); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_19); - /* "fuzzysearch/_generic_search.pyx":180 + /* "fuzzysearch/_generic_search.pyx":179 * if cand.subseq_index + n_skipped + 1 == _subseq_len: * yield Match(cand.start, index + 1, * cand.l_dist + n_skipped) # <<<<<<<<<<<<<< * # otherwise add a candidate skipping n_skipped * # subsequence chars */ - __pyx_t_20 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.l_dist); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_20); - __pyx_t_4 = PyNumber_Add(__pyx_t_20, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 180; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.l_dist); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_8 = PyNumber_Add(__pyx_t_18, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - /* "fuzzysearch/_generic_search.pyx":179 + /* "fuzzysearch/_generic_search.pyx":178 * # a match * if cand.subseq_index + n_skipped + 1 == _subseq_len: * yield Match(cand.start, index + 1, # <<<<<<<<<<<<<< * cand.l_dist + n_skipped) * # otherwise add a candidate skipping n_skipped */ - __pyx_t_20 = PyTuple_New(3); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_20); - PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_24); + __pyx_t_18 = PyTuple_New(3); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_18); + PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_24); __Pyx_GIVEREF(__pyx_t_24); - PyTuple_SET_ITEM(__pyx_t_20, 1, __pyx_t_21); - __Pyx_GIVEREF(__pyx_t_21); - PyTuple_SET_ITEM(__pyx_t_20, 2, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_18, 1, __pyx_t_19); + __Pyx_GIVEREF(__pyx_t_19); + PyTuple_SET_ITEM(__pyx_t_18, 2, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); __pyx_t_24 = 0; - __pyx_t_21 = 0; - __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_18, __pyx_t_20, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_4); + __pyx_t_19 = 0; + __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_18, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; - __Pyx_XGIVEREF(__pyx_t_1); - __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __pyx_r = __pyx_t_8; + __pyx_t_8 = 0; + __Pyx_XGIVEREF(__pyx_t_4); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_4; __pyx_cur_scope->__pyx_t_7 = __pyx_t_5; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_7; - __pyx_cur_scope->__pyx_t_2 = __pyx_t_12; + __Pyx_XGIVEREF(__pyx_t_9); + __pyx_cur_scope->__pyx_t_8 = __pyx_t_9; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_10; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_11; __pyx_cur_scope->__pyx_t_3 = __pyx_t_13; __pyx_cur_scope->__pyx_t_4 = __pyx_t_14; - __pyx_cur_scope->__pyx_t_5 = __pyx_t_16; - __pyx_cur_scope->__pyx_t_6 = __pyx_t_17; - __Pyx_XGIVEREF(__pyx_t_19); - __pyx_cur_scope->__pyx_t_8 = __pyx_t_19; + __pyx_cur_scope->__pyx_t_5 = __pyx_t_15; + __pyx_cur_scope->__pyx_t_6 = __pyx_t_16; __pyx_cur_scope->__pyx_t_9 = __pyx_t_23; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); /* return from generator, yielding value */ __pyx_generator->resume_label = 4; return __pyx_r; - __pyx_L33_resume_from_yield:; - __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_L32_resume_from_yield:; + __pyx_t_4 = __pyx_cur_scope->__pyx_t_0; __pyx_cur_scope->__pyx_t_0 = 0; - __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_4); __pyx_t_5 = __pyx_cur_scope->__pyx_t_7; - __pyx_t_7 = __pyx_cur_scope->__pyx_t_1; - __pyx_t_12 = __pyx_cur_scope->__pyx_t_2; + __pyx_t_9 = __pyx_cur_scope->__pyx_t_8; + __pyx_cur_scope->__pyx_t_8 = 0; + __Pyx_XGOTREF(__pyx_t_9); + __pyx_t_10 = __pyx_cur_scope->__pyx_t_1; + __pyx_t_11 = __pyx_cur_scope->__pyx_t_2; __pyx_t_13 = __pyx_cur_scope->__pyx_t_3; __pyx_t_14 = __pyx_cur_scope->__pyx_t_4; - __pyx_t_16 = __pyx_cur_scope->__pyx_t_5; - __pyx_t_17 = __pyx_cur_scope->__pyx_t_6; - __pyx_t_19 = __pyx_cur_scope->__pyx_t_8; - __pyx_cur_scope->__pyx_t_8 = 0; - __Pyx_XGOTREF(__pyx_t_19); + __pyx_t_15 = __pyx_cur_scope->__pyx_t_5; + __pyx_t_16 = __pyx_cur_scope->__pyx_t_6; __pyx_t_23 = __pyx_cur_scope->__pyx_t_9; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 179; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - goto __pyx_L32; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 178; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + goto __pyx_L31; } /*else*/ { - /* "fuzzysearch/_generic_search.pyx":185 + /* "fuzzysearch/_generic_search.pyx":184 * else: * new_candidates[n_new_candidates] = GenericSearchCandidate( * cand.start, cand.subseq_index + 1 + n_skipped, # <<<<<<<<<<<<<< * cand.l_dist + n_skipped, cand.n_subs, * cand.n_ins, cand.n_dels + n_skipped, */ - __pyx_t_15.start = __pyx_cur_scope->__pyx_v_cand.start; - __pyx_t_4 = __Pyx_PyInt_From_long((__pyx_cur_scope->__pyx_v_cand.subseq_index + 1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_20 = PyNumber_Add(__pyx_t_4, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_26 = __Pyx_PyInt_As_int(__pyx_t_20); if (unlikely((__pyx_t_26 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __pyx_t_15.subseq_index = __pyx_t_26; + __pyx_t_17.start = __pyx_cur_scope->__pyx_v_cand.start; + __pyx_t_8 = __Pyx_PyInt_From_long((__pyx_cur_scope->__pyx_v_cand.subseq_index + 1)); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_18 = PyNumber_Add(__pyx_t_8, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_18); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_26 = __Pyx_PyInt_As_int(__pyx_t_18); if (unlikely((__pyx_t_26 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __pyx_t_17.subseq_index = __pyx_t_26; - /* "fuzzysearch/_generic_search.pyx":186 + /* "fuzzysearch/_generic_search.pyx":185 * new_candidates[n_new_candidates] = GenericSearchCandidate( * cand.start, cand.subseq_index + 1 + n_skipped, * cand.l_dist + n_skipped, cand.n_subs, # <<<<<<<<<<<<<< * cand.n_ins, cand.n_dels + n_skipped, * ) */ - __pyx_t_20 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.l_dist); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_20); - __pyx_t_4 = PyNumber_Add(__pyx_t_20, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __pyx_t_26 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_26 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_15.l_dist = __pyx_t_26; - __pyx_t_15.n_subs = __pyx_cur_scope->__pyx_v_cand.n_subs; + __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.l_dist); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_8 = PyNumber_Add(__pyx_t_18, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __pyx_t_26 = __Pyx_PyInt_As_int(__pyx_t_8); if (unlikely((__pyx_t_26 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 185; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_17.l_dist = __pyx_t_26; + __pyx_t_17.n_subs = __pyx_cur_scope->__pyx_v_cand.n_subs; - /* "fuzzysearch/_generic_search.pyx":187 + /* "fuzzysearch/_generic_search.pyx":186 * cand.start, cand.subseq_index + 1 + n_skipped, * cand.l_dist + n_skipped, cand.n_subs, * cand.n_ins, cand.n_dels + n_skipped, # <<<<<<<<<<<<<< * ) * n_new_candidates += 1 */ - __pyx_t_15.n_ins = __pyx_cur_scope->__pyx_v_cand.n_ins; - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.n_dels); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_20 = PyNumber_Add(__pyx_t_4, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_26 = __Pyx_PyInt_As_int(__pyx_t_20); if (unlikely((__pyx_t_26 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __pyx_t_15.n_dels = __pyx_t_26; + __pyx_t_17.n_ins = __pyx_cur_scope->__pyx_v_cand.n_ins; + __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.n_dels); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_18 = PyNumber_Add(__pyx_t_8, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_18); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_26 = __Pyx_PyInt_As_int(__pyx_t_18); if (unlikely((__pyx_t_26 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __pyx_t_17.n_dels = __pyx_t_26; - /* "fuzzysearch/_generic_search.pyx":184 + /* "fuzzysearch/_generic_search.pyx":183 * # subsequence chars * else: * new_candidates[n_new_candidates] = GenericSearchCandidate( # <<<<<<<<<<<<<< * cand.start, cand.subseq_index + 1 + n_skipped, * cand.l_dist + n_skipped, cand.n_subs, */ - (__pyx_cur_scope->__pyx_v_new_candidates[__pyx_cur_scope->__pyx_v_n_new_candidates]) = __pyx_t_15; + (__pyx_cur_scope->__pyx_v_new_candidates[__pyx_cur_scope->__pyx_v_n_new_candidates]) = __pyx_t_17; - /* "fuzzysearch/_generic_search.pyx":189 + /* "fuzzysearch/_generic_search.pyx":188 * cand.n_ins, cand.n_dels + n_skipped, * ) * n_new_candidates += 1 # <<<<<<<<<<<<<< @@ -2812,26 +2588,26 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener */ __pyx_cur_scope->__pyx_v_n_new_candidates = (__pyx_cur_scope->__pyx_v_n_new_candidates + 1); } - __pyx_L32:; + __pyx_L31:; - /* "fuzzysearch/_generic_search.pyx":190 + /* "fuzzysearch/_generic_search.pyx":189 * ) * n_new_candidates += 1 * break # <<<<<<<<<<<<<< * # note: if the above loop ends without a break, that means that * # no candidate could be added / yielded by skipping sub-sequence */ - goto __pyx_L29_break; + goto __pyx_L28_break; } } - __pyx_L29_break:; - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + __pyx_L28_break:; + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } - __pyx_L19:; - __pyx_L15_continue:; + __pyx_L18:; + __pyx_L14_continue:; } - /* "fuzzysearch/_generic_search.pyx":196 + /* "fuzzysearch/_generic_search.pyx":195 * * # new_candidates = candidates; candidates = [] * _tmp = candidates # <<<<<<<<<<<<<< @@ -2840,7 +2616,7 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener */ __pyx_cur_scope->__pyx_v__tmp = __pyx_cur_scope->__pyx_v_candidates; - /* "fuzzysearch/_generic_search.pyx":197 + /* "fuzzysearch/_generic_search.pyx":196 * # new_candidates = candidates; candidates = [] * _tmp = candidates * candidates = new_candidates # <<<<<<<<<<<<<< @@ -2849,7 +2625,7 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener */ __pyx_cur_scope->__pyx_v_candidates = __pyx_cur_scope->__pyx_v_new_candidates; - /* "fuzzysearch/_generic_search.pyx":198 + /* "fuzzysearch/_generic_search.pyx":197 * _tmp = candidates * candidates = new_candidates * new_candidates = _tmp # <<<<<<<<<<<<<< @@ -2858,7 +2634,7 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener */ __pyx_cur_scope->__pyx_v_new_candidates = __pyx_cur_scope->__pyx_v__tmp; - /* "fuzzysearch/_generic_search.pyx":199 + /* "fuzzysearch/_generic_search.pyx":198 * candidates = new_candidates * new_candidates = _tmp * n_candidates = n_new_candidates # <<<<<<<<<<<<<< @@ -2867,7 +2643,7 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener */ __pyx_cur_scope->__pyx_v_n_candidates = __pyx_cur_scope->__pyx_v_n_new_candidates; - /* "fuzzysearch/_generic_search.pyx":200 + /* "fuzzysearch/_generic_search.pyx":199 * new_candidates = _tmp * n_candidates = n_new_candidates * n_new_candidates = 0 # <<<<<<<<<<<<<< @@ -2876,17 +2652,17 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener */ __pyx_cur_scope->__pyx_v_n_new_candidates = 0; - /* "fuzzysearch/_generic_search.pyx":202 + /* "fuzzysearch/_generic_search.pyx":201 * n_new_candidates = 0 * * if have_realloced: # <<<<<<<<<<<<<< * have_realloced = False * _tmp = realloc(new_candidates, alloc_size * sizeof(GenericSearchCandidate)) */ - __pyx_t_6 = (__pyx_cur_scope->__pyx_v_have_realloced != 0); - if (__pyx_t_6) { + __pyx_t_3 = (__pyx_cur_scope->__pyx_v_have_realloced != 0); + if (__pyx_t_3) { - /* "fuzzysearch/_generic_search.pyx":203 + /* "fuzzysearch/_generic_search.pyx":202 * * if have_realloced: * have_realloced = False # <<<<<<<<<<<<<< @@ -2895,43 +2671,36 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener */ __pyx_cur_scope->__pyx_v_have_realloced = 0; - /* "fuzzysearch/_generic_search.pyx":204 + /* "fuzzysearch/_generic_search.pyx":203 * if have_realloced: * have_realloced = False * _tmp = realloc(new_candidates, alloc_size * sizeof(GenericSearchCandidate)) # <<<<<<<<<<<<<< * if _tmp is NULL: * raise MemoryError() */ - __pyx_t_19 = __Pyx_PyInt_FromSize_t((sizeof(struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate))); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_19); - __pyx_t_20 = PyNumber_Multiply(__pyx_cur_scope->__pyx_v_alloc_size, __pyx_t_19); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; - __pyx_t_11 = __Pyx_PyInt_As_size_t(__pyx_t_20); if (unlikely((__pyx_t_11 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 204; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __pyx_cur_scope->__pyx_v__tmp = ((struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate *)realloc(__pyx_cur_scope->__pyx_v_new_candidates, __pyx_t_11)); + __pyx_cur_scope->__pyx_v__tmp = ((struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate *)realloc(__pyx_cur_scope->__pyx_v_new_candidates, (__pyx_cur_scope->__pyx_v_alloc_size * (sizeof(struct __pyx_t_11fuzzysearch_15_generic_search_GenericSearchCandidate))))); - /* "fuzzysearch/_generic_search.pyx":205 + /* "fuzzysearch/_generic_search.pyx":204 * have_realloced = False * _tmp = realloc(new_candidates, alloc_size * sizeof(GenericSearchCandidate)) * if _tmp is NULL: # <<<<<<<<<<<<<< * raise MemoryError() * new_candidates = _tmp */ - __pyx_t_6 = ((__pyx_cur_scope->__pyx_v__tmp == NULL) != 0); - if (__pyx_t_6) { + __pyx_t_3 = ((__pyx_cur_scope->__pyx_v__tmp == NULL) != 0); + if (__pyx_t_3) { - /* "fuzzysearch/_generic_search.pyx":206 + /* "fuzzysearch/_generic_search.pyx":205 * _tmp = realloc(new_candidates, alloc_size * sizeof(GenericSearchCandidate)) * if _tmp is NULL: * raise MemoryError() # <<<<<<<<<<<<<< * new_candidates = _tmp * */ - PyErr_NoMemory(); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 206; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + PyErr_NoMemory(); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 205; __pyx_clineno = __LINE__; goto __pyx_L10_error;} } - /* "fuzzysearch/_generic_search.pyx":207 + /* "fuzzysearch/_generic_search.pyx":206 * if _tmp is NULL: * raise MemoryError() * new_candidates = _tmp # <<<<<<<<<<<<<< @@ -2939,11 +2708,11 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener * index += 1 */ __pyx_cur_scope->__pyx_v_new_candidates = __pyx_cur_scope->__pyx_v__tmp; - goto __pyx_L34; + goto __pyx_L33; } - __pyx_L34:; + __pyx_L33:; - /* "fuzzysearch/_generic_search.pyx":209 + /* "fuzzysearch/_generic_search.pyx":208 * new_candidates = _tmp * * index += 1 # <<<<<<<<<<<<<< @@ -2952,20 +2721,20 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener */ __pyx_cur_scope->__pyx_v_index = (__pyx_cur_scope->__pyx_v_index + 1); } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "fuzzysearch/_generic_search.pyx":211 + /* "fuzzysearch/_generic_search.pyx":210 * index += 1 * * for n_cand in xrange(n_candidates): # <<<<<<<<<<<<<< * cand = candidates[n_cand] * # note: index == length(sequence) */ - __pyx_t_16 = __pyx_cur_scope->__pyx_v_n_candidates; - for (__pyx_t_17 = 0; __pyx_t_17 < __pyx_t_16; __pyx_t_17+=1) { - __pyx_cur_scope->__pyx_v_n_cand = __pyx_t_17; + __pyx_t_13 = __pyx_cur_scope->__pyx_v_n_candidates; + for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_13; __pyx_t_11+=1) { + __pyx_cur_scope->__pyx_v_n_cand = __pyx_t_11; - /* "fuzzysearch/_generic_search.pyx":212 + /* "fuzzysearch/_generic_search.pyx":211 * * for n_cand in xrange(n_candidates): * cand = candidates[n_cand] # <<<<<<<<<<<<<< @@ -2974,184 +2743,196 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener */ __pyx_cur_scope->__pyx_v_cand = (__pyx_cur_scope->__pyx_v_candidates[__pyx_cur_scope->__pyx_v_n_cand]); - /* "fuzzysearch/_generic_search.pyx":214 + /* "fuzzysearch/_generic_search.pyx":213 * cand = candidates[n_cand] * # note: index == length(sequence) * n_skipped = _subseq_len - cand.subseq_index # <<<<<<<<<<<<<< * if cand.n_dels + n_skipped <= c_max_deletions and \ * cand.l_dist + n_skipped <= c_max_l_dist: */ - __pyx_t_1 = __Pyx_PyInt_From_int((__pyx_cur_scope->__pyx_v__subseq_len - __pyx_cur_scope->__pyx_v_cand.subseq_index)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = __Pyx_PyInt_FromSize_t((__pyx_cur_scope->__pyx_v__subseq_len - __pyx_cur_scope->__pyx_v_cand.subseq_index)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 213; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_4); __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_n_skipped); - __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_n_skipped, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __pyx_t_1 = 0; + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_n_skipped, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_4 = 0; - /* "fuzzysearch/_generic_search.pyx":215 + /* "fuzzysearch/_generic_search.pyx":214 * # note: index == length(sequence) * n_skipped = _subseq_len - cand.subseq_index * if cand.n_dels + n_skipped <= c_max_deletions and \ # <<<<<<<<<<<<<< * cand.l_dist + n_skipped <= c_max_l_dist: * yield Match(cand.start, index, cand.l_dist + n_skipped) */ - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.n_dels); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_20 = PyNumber_Add(__pyx_t_1, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_t_20, __pyx_cur_scope->__pyx_v_c_max_deletions, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_6) { + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.n_dels); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = PyNumber_Add(__pyx_t_4, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyInt_From_unsigned_int(__pyx_cur_scope->__pyx_v_c_max_deletions); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_18 = PyObject_RichCompare(__pyx_t_9, __pyx_t_4, Py_LE); __Pyx_XGOTREF(__pyx_t_18); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_18); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 214; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + if (__pyx_t_3) { - /* "fuzzysearch/_generic_search.pyx":216 + /* "fuzzysearch/_generic_search.pyx":215 * n_skipped = _subseq_len - cand.subseq_index * if cand.n_dels + n_skipped <= c_max_deletions and \ * cand.l_dist + n_skipped <= c_max_l_dist: # <<<<<<<<<<<<<< * yield Match(cand.start, index, cand.l_dist + n_skipped) * */ - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.l_dist); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_20 = PyNumber_Add(__pyx_t_1, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_20); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_RichCompare(__pyx_t_20, __pyx_cur_scope->__pyx_v_c_max_l_dist, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_22 = __pyx_t_2; + __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.l_dist); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_4 = PyNumber_Add(__pyx_t_18, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __pyx_t_18 = __Pyx_PyInt_From_unsigned_int(__pyx_cur_scope->__pyx_v_c_max_l_dist); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_9 = PyObject_RichCompare(__pyx_t_4, __pyx_t_18, Py_LE); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + __pyx_t_20 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_20 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_21 = __pyx_t_20; } else { - __pyx_t_22 = __pyx_t_6; + __pyx_t_21 = __pyx_t_3; } - if (__pyx_t_22) { + if (__pyx_t_21) { - /* "fuzzysearch/_generic_search.pyx":217 + /* "fuzzysearch/_generic_search.pyx":216 * if cand.n_dels + n_skipped <= c_max_deletions and \ * cand.l_dist + n_skipped <= c_max_l_dist: * yield Match(cand.start, index, cand.l_dist + n_skipped) # <<<<<<<<<<<<<< * * finally: */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_Match); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L11_error;} + __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_Match); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.start); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_18); + __pyx_t_4 = __Pyx_PyInt_FromSize_t(__pyx_cur_scope->__pyx_v_index); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.l_dist); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = PyNumber_Add(__pyx_t_8, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L10_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_20 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.start); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_20); - __pyx_t_19 = __Pyx_PyInt_From_unsigned_int(__pyx_cur_scope->__pyx_v_index); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_19); - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_cur_scope->__pyx_v_cand.l_dist); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_18 = PyNumber_Add(__pyx_t_4, __pyx_cur_scope->__pyx_v_n_skipped); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_18); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_20); - __Pyx_GIVEREF(__pyx_t_20); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_19); - __Pyx_GIVEREF(__pyx_t_19); - PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_18); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_8); + PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_18); __Pyx_GIVEREF(__pyx_t_18); - __pyx_t_20 = 0; - __pyx_t_19 = 0; + PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); __pyx_t_18 = 0; - __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - __Pyx_GOTREF(__pyx_t_18); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_r = __pyx_t_18; - __pyx_t_18 = 0; - __pyx_cur_scope->__pyx_t_5 = __pyx_t_16; - __pyx_cur_scope->__pyx_t_6 = __pyx_t_17; + __pyx_t_4 = 0; + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_8, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_11; + __pyx_cur_scope->__pyx_t_3 = __pyx_t_13; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); /* return from generator, yielding value */ __pyx_generator->resume_label = 5; return __pyx_r; - __pyx_L39_resume_from_yield:; - __pyx_t_16 = __pyx_cur_scope->__pyx_t_5; - __pyx_t_17 = __pyx_cur_scope->__pyx_t_6; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 217; __pyx_clineno = __LINE__; goto __pyx_L11_error;} - goto __pyx_L38; + __pyx_L38_resume_from_yield:; + __pyx_t_11 = __pyx_cur_scope->__pyx_t_2; + __pyx_t_13 = __pyx_cur_scope->__pyx_t_3; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 216; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + goto __pyx_L37; } - __pyx_L38:; + __pyx_L37:; } } - /* "fuzzysearch/_generic_search.pyx":220 + /* "fuzzysearch/_generic_search.pyx":219 * * finally: * free(candidates) # <<<<<<<<<<<<<< * free(new_candidates) + * */ /*finally:*/ { /*normal exit:*/{ free(__pyx_cur_scope->__pyx_v_candidates); - /* "fuzzysearch/_generic_search.pyx":221 + /* "fuzzysearch/_generic_search.pyx":220 * finally: * free(candidates) * free(new_candidates) # <<<<<<<<<<<<<< + * + * */ free(__pyx_cur_scope->__pyx_v_new_candidates); - goto __pyx_L12; + goto __pyx_L11; } /*exception exit:*/{ - __pyx_L11_error:; - __pyx_t_28 = 0; __pyx_t_29 = 0; __pyx_t_30 = 0; __pyx_t_31 = 0; __pyx_t_32 = 0; __pyx_t_33 = 0; + __pyx_L10_error:; + __pyx_t_29 = 0; __pyx_t_30 = 0; __pyx_t_31 = 0; __pyx_t_32 = 0; __pyx_t_33 = 0; __pyx_t_34 = 0; __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0; - __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; - __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; - if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_31, &__pyx_t_32, &__pyx_t_33); - if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_28, &__pyx_t_29, &__pyx_t_30) < 0)) __Pyx_ErrFetch(&__pyx_t_28, &__pyx_t_29, &__pyx_t_30); - __Pyx_XGOTREF(__pyx_t_28); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_32, &__pyx_t_33, &__pyx_t_34); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_29, &__pyx_t_30, &__pyx_t_31) < 0)) __Pyx_ErrFetch(&__pyx_t_29, &__pyx_t_30, &__pyx_t_31); __Pyx_XGOTREF(__pyx_t_29); __Pyx_XGOTREF(__pyx_t_30); __Pyx_XGOTREF(__pyx_t_31); __Pyx_XGOTREF(__pyx_t_32); __Pyx_XGOTREF(__pyx_t_33); - __pyx_t_16 = __pyx_lineno; __pyx_t_17 = __pyx_clineno; __pyx_t_27 = __pyx_filename; + __Pyx_XGOTREF(__pyx_t_34); + __pyx_t_26 = __pyx_lineno; __pyx_t_27 = __pyx_clineno; __pyx_t_28 = __pyx_filename; { - /* "fuzzysearch/_generic_search.pyx":220 + /* "fuzzysearch/_generic_search.pyx":219 * * finally: * free(candidates) # <<<<<<<<<<<<<< * free(new_candidates) + * */ free(__pyx_cur_scope->__pyx_v_candidates); - /* "fuzzysearch/_generic_search.pyx":221 + /* "fuzzysearch/_generic_search.pyx":220 * finally: * free(candidates) * free(new_candidates) # <<<<<<<<<<<<<< + * + * */ free(__pyx_cur_scope->__pyx_v_new_candidates); } if (PY_MAJOR_VERSION >= 3) { - __Pyx_XGIVEREF(__pyx_t_31); __Pyx_XGIVEREF(__pyx_t_32); __Pyx_XGIVEREF(__pyx_t_33); - __Pyx_ExceptionReset(__pyx_t_31, __pyx_t_32, __pyx_t_33); + __Pyx_XGIVEREF(__pyx_t_34); + __Pyx_ExceptionReset(__pyx_t_32, __pyx_t_33, __pyx_t_34); } - __Pyx_XGIVEREF(__pyx_t_28); __Pyx_XGIVEREF(__pyx_t_29); __Pyx_XGIVEREF(__pyx_t_30); - __Pyx_ErrRestore(__pyx_t_28, __pyx_t_29, __pyx_t_30); - __pyx_t_28 = 0; __pyx_t_29 = 0; __pyx_t_30 = 0; __pyx_t_31 = 0; __pyx_t_32 = 0; __pyx_t_33 = 0; - __pyx_lineno = __pyx_t_16; __pyx_clineno = __pyx_t_17; __pyx_filename = __pyx_t_27; + __Pyx_XGIVEREF(__pyx_t_31); + __Pyx_ErrRestore(__pyx_t_29, __pyx_t_30, __pyx_t_31); + __pyx_t_29 = 0; __pyx_t_30 = 0; __pyx_t_31 = 0; __pyx_t_32 = 0; __pyx_t_33 = 0; __pyx_t_34 = 0; + __pyx_lineno = __pyx_t_26; __pyx_clineno = __pyx_t_27; __pyx_filename = __pyx_t_28; goto __pyx_L1_error; } - __pyx_L12:; + __pyx_L11:; } - /* "fuzzysearch/_generic_search.pyx":23 + /* "fuzzysearch/_generic_search.pyx":24 * * * def c_find_near_matches_generic_linear_programming(subsequence, sequence, # <<<<<<<<<<<<<< @@ -3165,10 +2946,10 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); __Pyx_XDECREF(__pyx_t_18); __Pyx_XDECREF(__pyx_t_19); - __Pyx_XDECREF(__pyx_t_20); - __Pyx_XDECREF(__pyx_t_21); __Pyx_XDECREF(__pyx_t_24); __Pyx_AddTraceback("c_find_near_matches_generic_linear_programming", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; @@ -3178,6 +2959,969 @@ static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_2generator(__pyx_Gener __Pyx_RefNannyFinishContext(); return NULL; } +static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_5generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* "fuzzysearch/_generic_search.pyx":223 + * + * + * def c_find_near_matches_generic_ngrams(subsequence, sequence, # <<<<<<<<<<<<<< + * max_substitutions, max_insertions, + * max_deletions, max_l_dist=None): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11fuzzysearch_15_generic_search_4c_find_near_matches_generic_ngrams(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_11fuzzysearch_15_generic_search_3c_find_near_matches_generic_ngrams[] = "search for near-matches of subsequence in sequence\n\n This searches for near-matches, where the nearly-matching parts of the\n sequence must meet the following limitations (relative to the subsequence):\n\n * the maximum allowed number of character substitutions\n * the maximum allowed number of new characters inserted\n * and the maximum allowed number of character deletions\n * the total number of substitutions, insertions and deletions\n "; +static PyMethodDef __pyx_mdef_11fuzzysearch_15_generic_search_4c_find_near_matches_generic_ngrams = {__Pyx_NAMESTR("c_find_near_matches_generic_ngrams"), (PyCFunction)__pyx_pw_11fuzzysearch_15_generic_search_4c_find_near_matches_generic_ngrams, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_11fuzzysearch_15_generic_search_3c_find_near_matches_generic_ngrams)}; +static PyObject *__pyx_pw_11fuzzysearch_15_generic_search_4c_find_near_matches_generic_ngrams(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_subsequence = 0; + PyObject *__pyx_v_sequence = 0; + PyObject *__pyx_v_max_substitutions = 0; + PyObject *__pyx_v_max_insertions = 0; + PyObject *__pyx_v_max_deletions = 0; + PyObject *__pyx_v_max_l_dist = 0; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("c_find_near_matches_generic_ngrams (wrapper)", 0); + { + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_subsequence,&__pyx_n_s_sequence,&__pyx_n_s_max_substitutions,&__pyx_n_s_max_insertions,&__pyx_n_s_max_deletions,&__pyx_n_s_max_l_dist,0}; + PyObject* values[6] = {0,0,0,0,0,0}; + + /* "fuzzysearch/_generic_search.pyx":225 + * def c_find_near_matches_generic_ngrams(subsequence, sequence, + * max_substitutions, max_insertions, + * max_deletions, max_l_dist=None): # <<<<<<<<<<<<<< + * """search for near-matches of subsequence in sequence + * + */ + values[5] = ((PyObject *)Py_None); + if (unlikely(__pyx_kwds)) { + Py_ssize_t kw_args; + const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); + switch (pos_args) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_subsequence)) != 0)) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sequence)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("c_find_near_matches_generic_ngrams", 0, 5, 6, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 2: + if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_substitutions)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("c_find_near_matches_generic_ngrams", 0, 5, 6, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 3: + if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_insertions)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("c_find_near_matches_generic_ngrams", 0, 5, 6, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 4: + if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_deletions)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("c_find_near_matches_generic_ngrams", 0, 5, 6, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + case 5: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_l_dist); + if (value) { values[5] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "c_find_near_matches_generic_ngrams") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + values[3] = PyTuple_GET_ITEM(__pyx_args, 3); + values[2] = PyTuple_GET_ITEM(__pyx_args, 2); + values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_subsequence = values[0]; + __pyx_v_sequence = values[1]; + __pyx_v_max_substitutions = values[2]; + __pyx_v_max_insertions = values[3]; + __pyx_v_max_deletions = values[4]; + __pyx_v_max_l_dist = values[5]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("c_find_near_matches_generic_ngrams", 0, 5, 6, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("fuzzysearch._generic_search.c_find_near_matches_generic_ngrams", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_11fuzzysearch_15_generic_search_3c_find_near_matches_generic_ngrams(__pyx_self, __pyx_v_subsequence, __pyx_v_sequence, __pyx_v_max_substitutions, __pyx_v_max_insertions, __pyx_v_max_deletions, __pyx_v_max_l_dist); + + /* "fuzzysearch/_generic_search.pyx":223 + * + * + * def c_find_near_matches_generic_ngrams(subsequence, sequence, # <<<<<<<<<<<<<< + * max_substitutions, max_insertions, + * max_deletions, max_l_dist=None): + */ + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11fuzzysearch_15_generic_search_3c_find_near_matches_generic_ngrams(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_subsequence, PyObject *__pyx_v_sequence, PyObject *__pyx_v_max_substitutions, PyObject *__pyx_v_max_insertions, PyObject *__pyx_v_max_deletions, PyObject *__pyx_v_max_l_dist) { + struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("c_find_near_matches_generic_ngrams", 0); + __pyx_cur_scope = (struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams *)__pyx_tp_new_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams(__pyx_ptype_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __Pyx_GOTREF(__pyx_cur_scope); + __pyx_cur_scope->__pyx_v_subsequence = __pyx_v_subsequence; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_subsequence); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_subsequence); + __pyx_cur_scope->__pyx_v_sequence = __pyx_v_sequence; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_sequence); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_sequence); + __pyx_cur_scope->__pyx_v_max_substitutions = __pyx_v_max_substitutions; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_max_substitutions); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_max_substitutions); + __pyx_cur_scope->__pyx_v_max_insertions = __pyx_v_max_insertions; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_max_insertions); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_max_insertions); + __pyx_cur_scope->__pyx_v_max_deletions = __pyx_v_max_deletions; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_max_deletions); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_max_deletions); + __pyx_cur_scope->__pyx_v_max_l_dist = __pyx_v_max_l_dist; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_max_l_dist); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_max_l_dist); + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_11fuzzysearch_15_generic_search_5generator1, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("fuzzysearch._generic_search.c_find_near_matches_generic_ngrams", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_11fuzzysearch_15_generic_search_5generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams *__pyx_cur_scope = ((struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + Py_ssize_t __pyx_t_5; + unsigned int __pyx_t_6; + unsigned int __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + char *__pyx_t_10; + long __pyx_t_11; + PyObject *(*__pyx_t_12)(PyObject *); + size_t __pyx_t_13; + int __pyx_t_14; + long __pyx_t_15; + PyObject *__pyx_t_16 = NULL; + Py_ssize_t __pyx_t_17; + PyObject *(*__pyx_t_18)(PyObject *); + PyObject *__pyx_t_19 = NULL; + PyObject *__pyx_t_20 = NULL; + int __pyx_t_21; + char const *__pyx_t_22; + PyObject *__pyx_t_23 = NULL; + PyObject *__pyx_t_24 = NULL; + PyObject *__pyx_t_25 = NULL; + PyObject *__pyx_t_26 = NULL; + PyObject *__pyx_t_27 = NULL; + PyObject *__pyx_t_28 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L18_resume_from_yield; + default: /* CPython raises the right error here */ + __Pyx_RefNannyFinishContext(); + return NULL; + } + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "fuzzysearch/_generic_search.pyx":236 + * * the total number of substitutions, insertions and deletions + * """ + * if not isinstance(sequence, ALLOWED_TYPES): # <<<<<<<<<<<<<< + * raise TypeError('sequence is of invalid type %s' % type(subsequence)) + * if not isinstance(subsequence, ALLOWED_TYPES): + */ + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_ALLOWED_TYPES); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_IsInstance(__pyx_cur_scope->__pyx_v_sequence, __pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = ((!(__pyx_t_2 != 0)) != 0); + if (__pyx_t_3) { + + /* "fuzzysearch/_generic_search.pyx":237 + * """ + * if not isinstance(sequence, ALLOWED_TYPES): + * raise TypeError('sequence is of invalid type %s' % type(subsequence)) # <<<<<<<<<<<<<< + * if not isinstance(subsequence, ALLOWED_TYPES): + * raise TypeError('subsequence is of invalid type %s' % type(subsequence)) + */ + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_sequence_is_of_invalid_type_s, ((PyObject *)Py_TYPE(__pyx_cur_scope->__pyx_v_subsequence))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + + /* "fuzzysearch/_generic_search.pyx":238 + * if not isinstance(sequence, ALLOWED_TYPES): + * raise TypeError('sequence is of invalid type %s' % type(subsequence)) + * if not isinstance(subsequence, ALLOWED_TYPES): # <<<<<<<<<<<<<< + * raise TypeError('subsequence is of invalid type %s' % type(subsequence)) + * + */ + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_ALLOWED_TYPES); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_IsInstance(__pyx_cur_scope->__pyx_v_subsequence, __pyx_t_1); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 238; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_2 = ((!(__pyx_t_3 != 0)) != 0); + if (__pyx_t_2) { + + /* "fuzzysearch/_generic_search.pyx":239 + * raise TypeError('sequence is of invalid type %s' % type(subsequence)) + * if not isinstance(subsequence, ALLOWED_TYPES): + * raise TypeError('subsequence is of invalid type %s' % type(subsequence)) # <<<<<<<<<<<<<< + * + * if not subsequence: + */ + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_subsequence_is_of_invalid_type_s, ((PyObject *)Py_TYPE(__pyx_cur_scope->__pyx_v_subsequence))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + + /* "fuzzysearch/_generic_search.pyx":241 + * raise TypeError('subsequence is of invalid type %s' % type(subsequence)) + * + * if not subsequence: # <<<<<<<<<<<<<< + * raise ValueError('Given subsequence is empty!') + * + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_subsequence); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 241; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = ((!__pyx_t_2) != 0); + if (__pyx_t_3) { + + /* "fuzzysearch/_generic_search.pyx":242 + * + * if not subsequence: + * raise ValueError('Given subsequence is empty!') # <<<<<<<<<<<<<< + * + * # optimization: prepare some often used things in advance + */ + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + + /* "fuzzysearch/_generic_search.pyx":245 + * + * # optimization: prepare some often used things in advance + * cdef size_t _subseq_len = len(subsequence) # <<<<<<<<<<<<<< + * cdef size_t _subseq_len_minus_one = _subseq_len - 1 + * cdef size_t _seq_len = len(sequence) + */ + __pyx_t_5 = PyObject_Length(__pyx_cur_scope->__pyx_v_subsequence); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 245; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v__subseq_len = __pyx_t_5; + + /* "fuzzysearch/_generic_search.pyx":246 + * # optimization: prepare some often used things in advance + * cdef size_t _subseq_len = len(subsequence) + * cdef size_t _subseq_len_minus_one = _subseq_len - 1 # <<<<<<<<<<<<<< + * cdef size_t _seq_len = len(sequence) + * + */ + __pyx_cur_scope->__pyx_v__subseq_len_minus_one = (__pyx_cur_scope->__pyx_v__subseq_len - 1); + + /* "fuzzysearch/_generic_search.pyx":247 + * cdef size_t _subseq_len = len(subsequence) + * cdef size_t _subseq_len_minus_one = _subseq_len - 1 + * cdef size_t _seq_len = len(sequence) # <<<<<<<<<<<<<< + * + * cdef unsigned int c_max_substitutions = max_substitutions if max_substitutions is not None else (1<<29) + */ + __pyx_t_5 = PyObject_Length(__pyx_cur_scope->__pyx_v_sequence); if (unlikely(__pyx_t_5 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v__seq_len = __pyx_t_5; + + /* "fuzzysearch/_generic_search.pyx":249 + * cdef size_t _seq_len = len(sequence) + * + * cdef unsigned int c_max_substitutions = max_substitutions if max_substitutions is not None else (1<<29) # <<<<<<<<<<<<<< + * cdef unsigned int c_max_insertions = max_insertions if max_insertions is not None else (1<<29) + * cdef unsigned int c_max_deletions = max_deletions if max_deletions is not None else (1<<29) + */ + __pyx_t_3 = (__pyx_cur_scope->__pyx_v_max_substitutions != Py_None); + if ((__pyx_t_3 != 0)) { + __pyx_t_7 = __Pyx_PyInt_As_unsigned_int(__pyx_cur_scope->__pyx_v_max_substitutions); if (unlikely((__pyx_t_7 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 249; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __pyx_t_7; + } else { + __pyx_t_6 = 536870912; + } + __pyx_cur_scope->__pyx_v_c_max_substitutions = __pyx_t_6; + + /* "fuzzysearch/_generic_search.pyx":250 + * + * cdef unsigned int c_max_substitutions = max_substitutions if max_substitutions is not None else (1<<29) + * cdef unsigned int c_max_insertions = max_insertions if max_insertions is not None else (1<<29) # <<<<<<<<<<<<<< + * cdef unsigned int c_max_deletions = max_deletions if max_deletions is not None else (1<<29) + * + */ + __pyx_t_3 = (__pyx_cur_scope->__pyx_v_max_insertions != Py_None); + if ((__pyx_t_3 != 0)) { + __pyx_t_7 = __Pyx_PyInt_As_unsigned_int(__pyx_cur_scope->__pyx_v_max_insertions); if (unlikely((__pyx_t_7 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 250; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __pyx_t_7; + } else { + __pyx_t_6 = 536870912; + } + __pyx_cur_scope->__pyx_v_c_max_insertions = __pyx_t_6; + + /* "fuzzysearch/_generic_search.pyx":251 + * cdef unsigned int c_max_substitutions = max_substitutions if max_substitutions is not None else (1<<29) + * cdef unsigned int c_max_insertions = max_insertions if max_insertions is not None else (1<<29) + * cdef unsigned int c_max_deletions = max_deletions if max_deletions is not None else (1<<29) # <<<<<<<<<<<<<< + * + * # TODO: write a good comment + */ + __pyx_t_3 = (__pyx_cur_scope->__pyx_v_max_deletions != Py_None); + if ((__pyx_t_3 != 0)) { + __pyx_t_7 = __Pyx_PyInt_As_unsigned_int(__pyx_cur_scope->__pyx_v_max_deletions); if (unlikely((__pyx_t_7 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 251; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_6 = __pyx_t_7; + } else { + __pyx_t_6 = 536870912; + } + __pyx_cur_scope->__pyx_v_c_max_deletions = __pyx_t_6; + + /* "fuzzysearch/_generic_search.pyx":256 + * cdef unsigned int c_max_l_dist = min( + * max_l_dist if max_l_dist is not None else (1<<29), + * c_max_substitutions + c_max_insertions + c_max_deletions, # <<<<<<<<<<<<<< + * ) + * + */ + __pyx_t_6 = ((__pyx_cur_scope->__pyx_v_c_max_substitutions + __pyx_cur_scope->__pyx_v_c_max_insertions) + __pyx_cur_scope->__pyx_v_c_max_deletions); + + /* "fuzzysearch/_generic_search.pyx":255 + * # TODO: write a good comment + * cdef unsigned int c_max_l_dist = min( + * max_l_dist if max_l_dist is not None else (1<<29), # <<<<<<<<<<<<<< + * c_max_substitutions + c_max_insertions + c_max_deletions, + * ) + */ + __pyx_t_3 = (__pyx_cur_scope->__pyx_v_max_l_dist != Py_None); + if ((__pyx_t_3 != 0)) { + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_max_l_dist); + __pyx_t_1 = __pyx_cur_scope->__pyx_v_max_l_dist; + } else { + __Pyx_INCREF(__pyx_int_536870912); + __pyx_t_1 = __pyx_int_536870912; + } + + /* "fuzzysearch/_generic_search.pyx":256 + * cdef unsigned int c_max_l_dist = min( + * max_l_dist if max_l_dist is not None else (1<<29), + * c_max_substitutions + c_max_insertions + c_max_deletions, # <<<<<<<<<<<<<< + * ) + * + */ + __pyx_t_8 = __Pyx_PyInt_From_unsigned_int(__pyx_t_6); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = PyObject_RichCompare(__pyx_t_8, __pyx_t_1, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (__pyx_t_3) { + __pyx_t_9 = __Pyx_PyInt_From_unsigned_int(__pyx_t_6); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_4 = __pyx_t_9; + __pyx_t_9 = 0; + } else { + __Pyx_INCREF(__pyx_t_1); + __pyx_t_4 = __pyx_t_1; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_6 = __Pyx_PyInt_As_unsigned_int(__pyx_t_4); if (unlikely((__pyx_t_6 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 256; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_cur_scope->__pyx_v_c_max_l_dist = __pyx_t_6; + + /* "fuzzysearch/_generic_search.pyx":259 + * ) + * + * cdef char* c_sequence = sequence # <<<<<<<<<<<<<< + * cdef char* c_subsequence = subsequence + * cdef char* ngram_str + */ + __pyx_t_10 = __Pyx_PyObject_AsString(__pyx_cur_scope->__pyx_v_sequence); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_c_sequence = __pyx_t_10; + + /* "fuzzysearch/_generic_search.pyx":260 + * + * cdef char* c_sequence = sequence + * cdef char* c_subsequence = subsequence # <<<<<<<<<<<<<< + * cdef char* ngram_str + * + */ + __pyx_t_10 = __Pyx_PyObject_AsString(__pyx_cur_scope->__pyx_v_subsequence); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 260; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_c_subsequence = __pyx_t_10; + + /* "fuzzysearch/_generic_search.pyx":263 + * cdef char* ngram_str + * + * cdef size_t ngram_len = _subseq_len // (c_max_l_dist + 1) # <<<<<<<<<<<<<< + * if ngram_len == 0: + * raise ValueError('the subsequence length must be greater than max_l_dist') + */ + __pyx_t_11 = (__pyx_cur_scope->__pyx_v_c_max_l_dist + 1); + if (unlikely(__pyx_t_11 == 0)) { + #ifdef WITH_THREAD + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure(); + #endif + PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero"); + #ifdef WITH_THREAD + PyGILState_Release(__pyx_gilstate_save); + #endif + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 263; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_cur_scope->__pyx_v_ngram_len = (__pyx_cur_scope->__pyx_v__subseq_len / __pyx_t_11); + + /* "fuzzysearch/_generic_search.pyx":264 + * + * cdef size_t ngram_len = _subseq_len // (c_max_l_dist + 1) + * if ngram_len == 0: # <<<<<<<<<<<<<< + * raise ValueError('the subsequence length must be greater than max_l_dist') + * + */ + __pyx_t_3 = ((__pyx_cur_scope->__pyx_v_ngram_len == 0) != 0); + if (__pyx_t_3) { + + /* "fuzzysearch/_generic_search.pyx":265 + * cdef size_t ngram_len = _subseq_len // (c_max_l_dist + 1) + * if ngram_len == 0: + * raise ValueError('the subsequence length must be greater than max_l_dist') # <<<<<<<<<<<<<< + * + * ngram_str = malloc((ngram_len + 1) * sizeof(char)) + */ + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_Raise(__pyx_t_4, 0, 0, 0); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + + /* "fuzzysearch/_generic_search.pyx":267 + * raise ValueError('the subsequence length must be greater than max_l_dist') + * + * ngram_str = malloc((ngram_len + 1) * sizeof(char)) # <<<<<<<<<<<<<< + * if ngram_str is NULL: + * raise MemoryError() + */ + __pyx_cur_scope->__pyx_v_ngram_str = ((char *)malloc(((__pyx_cur_scope->__pyx_v_ngram_len + 1) * (sizeof(char))))); + + /* "fuzzysearch/_generic_search.pyx":268 + * + * ngram_str = malloc((ngram_len + 1) * sizeof(char)) + * if ngram_str is NULL: # <<<<<<<<<<<<<< + * raise MemoryError() + * + */ + __pyx_t_3 = ((__pyx_cur_scope->__pyx_v_ngram_str == NULL) != 0); + if (__pyx_t_3) { + + /* "fuzzysearch/_generic_search.pyx":269 + * ngram_str = malloc((ngram_len + 1) * sizeof(char)) + * if ngram_str is NULL: + * raise MemoryError() # <<<<<<<<<<<<<< + * + * cdef int index + */ + PyErr_NoMemory(); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 269; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + + /* "fuzzysearch/_generic_search.pyx":275 + * cdef char *match_ptr + * + * try: # <<<<<<<<<<<<<< + * ngram_str[ngram_len] = 0 + * + */ + /*try:*/ { + + /* "fuzzysearch/_generic_search.pyx":276 + * + * try: + * ngram_str[ngram_len] = 0 # <<<<<<<<<<<<<< + * + * for ngram_start in xrange(0, _subseq_len - ngram_len + 1, ngram_len): + */ + (__pyx_cur_scope->__pyx_v_ngram_str[__pyx_cur_scope->__pyx_v_ngram_len]) = 0; + + /* "fuzzysearch/_generic_search.pyx":278 + * ngram_str[ngram_len] = 0 + * + * for ngram_start in xrange(0, _subseq_len - ngram_len + 1, ngram_len): # <<<<<<<<<<<<<< + * strncpy(ngram_str, c_subsequence + ngram_start, ngram_len) + * + */ + __pyx_t_4 = __Pyx_PyInt_FromSize_t(((__pyx_cur_scope->__pyx_v__subseq_len - __pyx_cur_scope->__pyx_v_ngram_len) + 1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = __Pyx_PyInt_FromSize_t(__pyx_cur_scope->__pyx_v_ngram_len); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_9); + __Pyx_INCREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_int_0); + __Pyx_GIVEREF(__pyx_int_0); + PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_4 = 0; + __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_xrange, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) { + __pyx_t_9 = __pyx_t_1; __Pyx_INCREF(__pyx_t_9); __pyx_t_5 = 0; + __pyx_t_12 = NULL; + } else { + __pyx_t_5 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_12 = Py_TYPE(__pyx_t_9)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + for (;;) { + if (!__pyx_t_12 && PyList_CheckExact(__pyx_t_9)) { + if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_9)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + #endif + } else if (!__pyx_t_12 && PyTuple_CheckExact(__pyx_t_9)) { + if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_9)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + #else + __pyx_t_1 = PySequence_ITEM(__pyx_t_9, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + #endif + } else { + __pyx_t_1 = __pyx_t_12(__pyx_t_9); + if (unlikely(!__pyx_t_1)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_1); + } + __pyx_t_13 = __Pyx_PyInt_As_size_t(__pyx_t_1); if (unlikely((__pyx_t_13 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_cur_scope->__pyx_v_ngram_start = __pyx_t_13; + + /* "fuzzysearch/_generic_search.pyx":279 + * + * for ngram_start in xrange(0, _subseq_len - ngram_len + 1, ngram_len): + * strncpy(ngram_str, c_subsequence + ngram_start, ngram_len) # <<<<<<<<<<<<<< + * + * match_ptr = strstr(c_sequence, ngram_str) + */ + strncpy(__pyx_cur_scope->__pyx_v_ngram_str, (__pyx_cur_scope->__pyx_v_c_subsequence + __pyx_cur_scope->__pyx_v_ngram_start), __pyx_cur_scope->__pyx_v_ngram_len); + + /* "fuzzysearch/_generic_search.pyx":281 + * strncpy(ngram_str, c_subsequence + ngram_start, ngram_len) + * + * match_ptr = strstr(c_sequence, ngram_str) # <<<<<<<<<<<<<< + * while match_ptr != NULL: + * index = (match_ptr - c_sequence) + */ + __pyx_cur_scope->__pyx_v_match_ptr = strstr(__pyx_cur_scope->__pyx_v_c_sequence, __pyx_cur_scope->__pyx_v_ngram_str); + + /* "fuzzysearch/_generic_search.pyx":282 + * + * match_ptr = strstr(c_sequence, ngram_str) + * while match_ptr != NULL: # <<<<<<<<<<<<<< + * index = (match_ptr - c_sequence) + * small_search_start_index = max(0, index - (ngram_start + c_max_l_dist)) + */ + while (1) { + __pyx_t_3 = ((__pyx_cur_scope->__pyx_v_match_ptr != NULL) != 0); + if (!__pyx_t_3) break; + + /* "fuzzysearch/_generic_search.pyx":283 + * match_ptr = strstr(c_sequence, ngram_str) + * while match_ptr != NULL: + * index = (match_ptr - c_sequence) # <<<<<<<<<<<<<< + * small_search_start_index = max(0, index - (ngram_start + c_max_l_dist)) + * # try to expand left and/or right according to n_ngram + */ + __pyx_cur_scope->__pyx_v_index = (__pyx_cur_scope->__pyx_v_match_ptr - __pyx_cur_scope->__pyx_v_c_sequence); + + /* "fuzzysearch/_generic_search.pyx":284 + * while match_ptr != NULL: + * index = (match_ptr - c_sequence) + * small_search_start_index = max(0, index - (ngram_start + c_max_l_dist)) # <<<<<<<<<<<<<< + * # try to expand left and/or right according to n_ngram + * for match in c_find_near_matches_generic_linear_programming( + */ + __pyx_t_14 = (__pyx_cur_scope->__pyx_v_index - ((int)(__pyx_cur_scope->__pyx_v_ngram_start + __pyx_cur_scope->__pyx_v_c_max_l_dist))); + __pyx_t_11 = 0; + if (((__pyx_t_14 > __pyx_t_11) != 0)) { + __pyx_t_15 = __pyx_t_14; + } else { + __pyx_t_15 = __pyx_t_11; + } + __pyx_cur_scope->__pyx_v_small_search_start_index = __pyx_t_15; + + /* "fuzzysearch/_generic_search.pyx":286 + * small_search_start_index = max(0, index - (ngram_start + c_max_l_dist)) + * # try to expand left and/or right according to n_ngram + * for match in c_find_near_matches_generic_linear_programming( # <<<<<<<<<<<<<< + * subsequence, sequence[small_search_start_index:index - ngram_start + _subseq_len + c_max_l_dist], + * max_substitutions, max_insertions, max_deletions, c_max_l_dist, + */ + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_c_find_near_matches_generic_line); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_1); + + /* "fuzzysearch/_generic_search.pyx":287 + * # try to expand left and/or right according to n_ngram + * for match in c_find_near_matches_generic_linear_programming( + * subsequence, sequence[small_search_start_index:index - ngram_start + _subseq_len + c_max_l_dist], # <<<<<<<<<<<<<< + * max_substitutions, max_insertions, max_deletions, c_max_l_dist, + * ): + */ + __pyx_t_4 = __Pyx_PyObject_GetSlice(__pyx_cur_scope->__pyx_v_sequence, __pyx_cur_scope->__pyx_v_small_search_start_index, (((__pyx_cur_scope->__pyx_v_index - __pyx_cur_scope->__pyx_v_ngram_start) + __pyx_cur_scope->__pyx_v__subseq_len) + __pyx_cur_scope->__pyx_v_c_max_l_dist), NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 287; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_4); + + /* "fuzzysearch/_generic_search.pyx":288 + * for match in c_find_near_matches_generic_linear_programming( + * subsequence, sequence[small_search_start_index:index - ngram_start + _subseq_len + c_max_l_dist], + * max_substitutions, max_insertions, max_deletions, c_max_l_dist, # <<<<<<<<<<<<<< + * ): + * yield match._replace( + */ + __pyx_t_8 = __Pyx_PyInt_From_unsigned_int(__pyx_cur_scope->__pyx_v_c_max_l_dist); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 288; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_8); + + /* "fuzzysearch/_generic_search.pyx":286 + * small_search_start_index = max(0, index - (ngram_start + c_max_l_dist)) + * # try to expand left and/or right according to n_ngram + * for match in c_find_near_matches_generic_linear_programming( # <<<<<<<<<<<<<< + * subsequence, sequence[small_search_start_index:index - ngram_start + _subseq_len + c_max_l_dist], + * max_substitutions, max_insertions, max_deletions, c_max_l_dist, + */ + __pyx_t_16 = PyTuple_New(6); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_16); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_subsequence); + PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_cur_scope->__pyx_v_subsequence); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_subsequence); + PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_max_substitutions); + PyTuple_SET_ITEM(__pyx_t_16, 2, __pyx_cur_scope->__pyx_v_max_substitutions); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_max_substitutions); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_max_insertions); + PyTuple_SET_ITEM(__pyx_t_16, 3, __pyx_cur_scope->__pyx_v_max_insertions); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_max_insertions); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_max_deletions); + PyTuple_SET_ITEM(__pyx_t_16, 4, __pyx_cur_scope->__pyx_v_max_deletions); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_max_deletions); + PyTuple_SET_ITEM(__pyx_t_16, 5, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_t_4 = 0; + __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_16, NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + if (PyList_CheckExact(__pyx_t_8) || PyTuple_CheckExact(__pyx_t_8)) { + __pyx_t_16 = __pyx_t_8; __Pyx_INCREF(__pyx_t_16); __pyx_t_17 = 0; + __pyx_t_18 = NULL; + } else { + __pyx_t_17 = -1; __pyx_t_16 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_18 = Py_TYPE(__pyx_t_16)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + for (;;) { + if (!__pyx_t_18 && PyList_CheckExact(__pyx_t_16)) { + if (__pyx_t_17 >= PyList_GET_SIZE(__pyx_t_16)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_8 = PyList_GET_ITEM(__pyx_t_16, __pyx_t_17); __Pyx_INCREF(__pyx_t_8); __pyx_t_17++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + #else + __pyx_t_8 = PySequence_ITEM(__pyx_t_16, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + #endif + } else if (!__pyx_t_18 && PyTuple_CheckExact(__pyx_t_16)) { + if (__pyx_t_17 >= PyTuple_GET_SIZE(__pyx_t_16)) break; + #if CYTHON_COMPILING_IN_CPYTHON + __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_16, __pyx_t_17); __Pyx_INCREF(__pyx_t_8); __pyx_t_17++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + #else + __pyx_t_8 = PySequence_ITEM(__pyx_t_16, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + #endif + } else { + __pyx_t_8 = __pyx_t_18(__pyx_t_16); + if (unlikely(!__pyx_t_8)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 286; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_8); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_match); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_match, __pyx_t_8); + __Pyx_GIVEREF(__pyx_t_8); + __pyx_t_8 = 0; + + /* "fuzzysearch/_generic_search.pyx":290 + * max_substitutions, max_insertions, max_deletions, c_max_l_dist, + * ): + * yield match._replace( # <<<<<<<<<<<<<< + * start=match.start + small_search_start_index, + * end=match.end + small_search_start_index, + */ + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_match, __pyx_n_s_replace); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_1); + + /* "fuzzysearch/_generic_search.pyx":291 + * ): + * yield match._replace( + * start=match.start + small_search_start_index, # <<<<<<<<<<<<<< + * end=match.end + small_search_start_index, + * ) + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_match, __pyx_n_s_start); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_19 = __Pyx_PyInt_FromSize_t(__pyx_cur_scope->__pyx_v_small_search_start_index); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_20 = PyNumber_Add(__pyx_t_4, __pyx_t_19); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 291; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_start, __pyx_t_20) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + + /* "fuzzysearch/_generic_search.pyx":292 + * yield match._replace( + * start=match.start + small_search_start_index, + * end=match.end + small_search_start_index, # <<<<<<<<<<<<<< + * ) + * match_ptr = strstr(match_ptr + 1, ngram_str) + */ + __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_match, __pyx_n_s_end); if (unlikely(!__pyx_t_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_20); + __pyx_t_19 = __Pyx_PyInt_FromSize_t(__pyx_cur_scope->__pyx_v_small_search_start_index); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_4 = PyNumber_Add(__pyx_t_20, __pyx_t_19); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 292; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_end, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "fuzzysearch/_generic_search.pyx":290 + * max_substitutions, max_insertions, max_deletions, c_max_l_dist, + * ): + * yield match._replace( # <<<<<<<<<<<<<< + * start=match.start + small_search_start_index, + * end=match.end + small_search_start_index, + */ + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_5; + __Pyx_XGIVEREF(__pyx_t_9); + __pyx_cur_scope->__pyx_t_1 = __pyx_t_9; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_12; + __Pyx_XGIVEREF(__pyx_t_16); + __pyx_cur_scope->__pyx_t_3 = __pyx_t_16; + __pyx_cur_scope->__pyx_t_4 = __pyx_t_17; + __pyx_cur_scope->__pyx_t_5 = __pyx_t_18; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L18_resume_from_yield:; + __pyx_t_5 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_9 = __pyx_cur_scope->__pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = 0; + __Pyx_XGOTREF(__pyx_t_9); + __pyx_t_12 = __pyx_cur_scope->__pyx_t_2; + __pyx_t_16 = __pyx_cur_scope->__pyx_t_3; + __pyx_cur_scope->__pyx_t_3 = 0; + __Pyx_XGOTREF(__pyx_t_16); + __pyx_t_17 = __pyx_cur_scope->__pyx_t_4; + __pyx_t_18 = __pyx_cur_scope->__pyx_t_5; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 290; __pyx_clineno = __LINE__; goto __pyx_L10_error;} + } + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + + /* "fuzzysearch/_generic_search.pyx":294 + * end=match.end + small_search_start_index, + * ) + * match_ptr = strstr(match_ptr + 1, ngram_str) # <<<<<<<<<<<<<< + * + * finally: + */ + __pyx_cur_scope->__pyx_v_match_ptr = strstr((__pyx_cur_scope->__pyx_v_match_ptr + 1), __pyx_cur_scope->__pyx_v_ngram_str); + } + } + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + + /* "fuzzysearch/_generic_search.pyx":297 + * + * finally: + * free(ngram_str) # <<<<<<<<<<<<<< + */ + /*finally:*/ { + /*normal exit:*/{ + free(__pyx_cur_scope->__pyx_v_ngram_str); + goto __pyx_L11; + } + /*exception exit:*/{ + __pyx_L10_error:; + __pyx_t_23 = 0; __pyx_t_24 = 0; __pyx_t_25 = 0; __pyx_t_26 = 0; __pyx_t_27 = 0; __pyx_t_28 = 0; + __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_26, &__pyx_t_27, &__pyx_t_28); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_23, &__pyx_t_24, &__pyx_t_25) < 0)) __Pyx_ErrFetch(&__pyx_t_23, &__pyx_t_24, &__pyx_t_25); + __Pyx_XGOTREF(__pyx_t_23); + __Pyx_XGOTREF(__pyx_t_24); + __Pyx_XGOTREF(__pyx_t_25); + __Pyx_XGOTREF(__pyx_t_26); + __Pyx_XGOTREF(__pyx_t_27); + __Pyx_XGOTREF(__pyx_t_28); + __pyx_t_14 = __pyx_lineno; __pyx_t_21 = __pyx_clineno; __pyx_t_22 = __pyx_filename; + { + free(__pyx_cur_scope->__pyx_v_ngram_str); + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_26); + __Pyx_XGIVEREF(__pyx_t_27); + __Pyx_XGIVEREF(__pyx_t_28); + __Pyx_ExceptionReset(__pyx_t_26, __pyx_t_27, __pyx_t_28); + } + __Pyx_XGIVEREF(__pyx_t_23); + __Pyx_XGIVEREF(__pyx_t_24); + __Pyx_XGIVEREF(__pyx_t_25); + __Pyx_ErrRestore(__pyx_t_23, __pyx_t_24, __pyx_t_25); + __pyx_t_23 = 0; __pyx_t_24 = 0; __pyx_t_25 = 0; __pyx_t_26 = 0; __pyx_t_27 = 0; __pyx_t_28 = 0; + __pyx_lineno = __pyx_t_14; __pyx_clineno = __pyx_t_21; __pyx_filename = __pyx_t_22; + goto __pyx_L1_error; + } + __pyx_L11:; + } + + /* "fuzzysearch/_generic_search.pyx":223 + * + * + * def c_find_near_matches_generic_ngrams(subsequence, sequence, # <<<<<<<<<<<<<< + * max_substitutions, max_insertions, + * max_deletions, max_l_dist=None): + */ + + /* function exit code */ + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_16); + __Pyx_XDECREF(__pyx_t_19); + __Pyx_XDECREF(__pyx_t_20); + __Pyx_AddTraceback("c_find_near_matches_generic_ngrams", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_Generator_clear((PyObject*)__pyx_generator); + __Pyx_RefNannyFinishContext(); + return NULL; +} static struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming *__pyx_freelist_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming[8]; static int __pyx_freecount_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming = 0; @@ -3199,17 +3943,10 @@ static PyObject *__pyx_tp_new_11fuzzysearch_15_generic_search___pyx_scope_struct static void __pyx_tp_dealloc_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming(PyObject *o) { struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming *p = (struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming *)o; PyObject_GC_UnTrack(o); - Py_CLEAR(p->__pyx_v_alloc_size); - Py_CLEAR(p->__pyx_v_c_max_deletions); - Py_CLEAR(p->__pyx_v_c_max_insertions); - Py_CLEAR(p->__pyx_v_c_max_l_dist); - Py_CLEAR(p->__pyx_v_c_max_substitutions); - Py_CLEAR(p->__pyx_v_genexpr); Py_CLEAR(p->__pyx_v_max_deletions); Py_CLEAR(p->__pyx_v_max_insertions); Py_CLEAR(p->__pyx_v_max_l_dist); Py_CLEAR(p->__pyx_v_max_substitutions); - Py_CLEAR(p->__pyx_v_maxes_sum); Py_CLEAR(p->__pyx_v_n_skipped); Py_CLEAR(p->__pyx_v_sequence); Py_CLEAR(p->__pyx_v_subsequence); @@ -3225,24 +3962,6 @@ static void __pyx_tp_dealloc_11fuzzysearch_15_generic_search___pyx_scope_struct_ static int __pyx_tp_traverse_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming(PyObject *o, visitproc v, void *a) { int e; struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming *p = (struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming *)o; - if (p->__pyx_v_alloc_size) { - e = (*v)(p->__pyx_v_alloc_size, a); if (e) return e; - } - if (p->__pyx_v_c_max_deletions) { - e = (*v)(p->__pyx_v_c_max_deletions, a); if (e) return e; - } - if (p->__pyx_v_c_max_insertions) { - e = (*v)(p->__pyx_v_c_max_insertions, a); if (e) return e; - } - if (p->__pyx_v_c_max_l_dist) { - e = (*v)(p->__pyx_v_c_max_l_dist, a); if (e) return e; - } - if (p->__pyx_v_c_max_substitutions) { - e = (*v)(p->__pyx_v_c_max_substitutions, a); if (e) return e; - } - if (p->__pyx_v_genexpr) { - e = (*v)(p->__pyx_v_genexpr, a); if (e) return e; - } if (p->__pyx_v_max_deletions) { e = (*v)(p->__pyx_v_max_deletions, a); if (e) return e; } @@ -3255,9 +3974,6 @@ static int __pyx_tp_traverse_11fuzzysearch_15_generic_search___pyx_scope_struct_ if (p->__pyx_v_max_substitutions) { e = (*v)(p->__pyx_v_max_substitutions, a); if (e) return e; } - if (p->__pyx_v_maxes_sum) { - e = (*v)(p->__pyx_v_maxes_sum, a); if (e) return e; - } if (p->__pyx_v_n_skipped) { e = (*v)(p->__pyx_v_n_skipped, a); if (e) return e; } @@ -3279,24 +3995,6 @@ static int __pyx_tp_traverse_11fuzzysearch_15_generic_search___pyx_scope_struct_ static int __pyx_tp_clear_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming(PyObject *o) { PyObject* tmp; struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming *p = (struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming *)o; - tmp = ((PyObject*)p->__pyx_v_alloc_size); - p->__pyx_v_alloc_size = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_c_max_deletions); - p->__pyx_v_c_max_deletions = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_c_max_insertions); - p->__pyx_v_c_max_insertions = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_c_max_l_dist); - p->__pyx_v_c_max_l_dist = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_c_max_substitutions); - p->__pyx_v_c_max_substitutions = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_genexpr); - p->__pyx_v_genexpr = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_max_deletions); p->__pyx_v_max_deletions = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); @@ -3309,9 +4007,6 @@ static int __pyx_tp_clear_11fuzzysearch_15_generic_search___pyx_scope_struct__c_ tmp = ((PyObject*)p->__pyx_v_max_substitutions); p->__pyx_v_max_substitutions = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_maxes_sum); - p->__pyx_v_maxes_sum = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_n_skipped); p->__pyx_v_n_skipped = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); @@ -3389,14 +4084,14 @@ static PyTypeObject __pyx_type_11fuzzysearch_15_generic_search___pyx_scope_struc #endif }; -static struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr *__pyx_freelist_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr[8]; -static int __pyx_freecount_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr = 0; +static struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams *__pyx_freelist_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams[8]; +static int __pyx_freecount_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams = 0; -static PyObject *__pyx_tp_new_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { +static PyObject *__pyx_tp_new_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { PyObject *o; - if (likely((__pyx_freecount_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr)))) { - o = (PyObject*)__pyx_freelist_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr[--__pyx_freecount_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr]; - memset(o, 0, sizeof(struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr)); + if (likely((__pyx_freecount_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams)))) { + o = (PyObject*)__pyx_freelist_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams[--__pyx_freecount_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams]; + memset(o, 0, sizeof(struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams)); (void) PyObject_INIT(o, t); PyObject_GC_Track(o); } else { @@ -3406,55 +4101,97 @@ static PyObject *__pyx_tp_new_11fuzzysearch_15_generic_search___pyx_scope_struct return o; } -static void __pyx_tp_dealloc_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr(PyObject *o) { - struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr *)o; +static void __pyx_tp_dealloc_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams(PyObject *o) { + struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams *p = (struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams *)o; PyObject_GC_UnTrack(o); - Py_CLEAR(p->__pyx_outer_scope); - Py_CLEAR(p->__pyx_v_x); - Py_CLEAR(p->__pyx_t_0); - if ((__pyx_freecount_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr))) { - __pyx_freelist_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr[__pyx_freecount_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr++] = ((struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr *)o); + Py_CLEAR(p->__pyx_v_match); + Py_CLEAR(p->__pyx_v_max_deletions); + Py_CLEAR(p->__pyx_v_max_insertions); + Py_CLEAR(p->__pyx_v_max_l_dist); + Py_CLEAR(p->__pyx_v_max_substitutions); + Py_CLEAR(p->__pyx_v_sequence); + Py_CLEAR(p->__pyx_v_subsequence); + Py_CLEAR(p->__pyx_t_1); + Py_CLEAR(p->__pyx_t_3); + if ((__pyx_freecount_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams))) { + __pyx_freelist_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams[__pyx_freecount_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams++] = ((struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams *)o); } else { (*Py_TYPE(o)->tp_free)(o); } } -static int __pyx_tp_traverse_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr *)o; - if (p->__pyx_outer_scope) { - e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e; + struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams *p = (struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams *)o; + if (p->__pyx_v_match) { + e = (*v)(p->__pyx_v_match, a); if (e) return e; } - if (p->__pyx_v_x) { - e = (*v)(p->__pyx_v_x, a); if (e) return e; + if (p->__pyx_v_max_deletions) { + e = (*v)(p->__pyx_v_max_deletions, a); if (e) return e; } - if (p->__pyx_t_0) { - e = (*v)(p->__pyx_t_0, a); if (e) return e; + if (p->__pyx_v_max_insertions) { + e = (*v)(p->__pyx_v_max_insertions, a); if (e) return e; + } + if (p->__pyx_v_max_l_dist) { + e = (*v)(p->__pyx_v_max_l_dist, a); if (e) return e; + } + if (p->__pyx_v_max_substitutions) { + e = (*v)(p->__pyx_v_max_substitutions, a); if (e) return e; + } + if (p->__pyx_v_sequence) { + e = (*v)(p->__pyx_v_sequence, a); if (e) return e; + } + if (p->__pyx_v_subsequence) { + e = (*v)(p->__pyx_v_subsequence, a); if (e) return e; + } + if (p->__pyx_t_1) { + e = (*v)(p->__pyx_t_1, a); if (e) return e; + } + if (p->__pyx_t_3) { + e = (*v)(p->__pyx_t_3, a); if (e) return e; } return 0; } -static int __pyx_tp_clear_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr(PyObject *o) { +static int __pyx_tp_clear_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams(PyObject *o) { PyObject* tmp; - struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr *p = (struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr *)o; - tmp = ((PyObject*)p->__pyx_outer_scope); - p->__pyx_outer_scope = ((struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming *)Py_None); Py_INCREF(Py_None); + struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams *p = (struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams *)o; + tmp = ((PyObject*)p->__pyx_v_match); + p->__pyx_v_match = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_x); - p->__pyx_v_x = Py_None; Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_v_max_deletions); + p->__pyx_v_max_deletions = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_t_0); - p->__pyx_t_0 = Py_None; Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_v_max_insertions); + p->__pyx_v_max_insertions = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_max_l_dist); + p->__pyx_v_max_l_dist = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_max_substitutions); + p->__pyx_v_max_substitutions = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_sequence); + p->__pyx_v_sequence = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_subsequence); + p->__pyx_v_subsequence = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_t_1); + p->__pyx_t_1 = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_t_3); + p->__pyx_t_3 = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyTypeObject __pyx_type_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr = { +static PyTypeObject __pyx_type_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("fuzzysearch._generic_search.__pyx_scope_struct_1_genexpr"), /*tp_name*/ - sizeof(struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr), /*tp_basicsize*/ + __Pyx_NAMESTR("fuzzysearch._generic_search.__pyx_scope_struct_1_c_find_near_matches_generic_ngrams"), /*tp_name*/ + sizeof(struct __pyx_obj_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr, /*tp_dealloc*/ + __pyx_tp_dealloc_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -3475,8 +4212,8 @@ static PyTypeObject __pyx_type_11fuzzysearch_15_generic_search___pyx_scope_struc 0, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - __pyx_tp_traverse_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr, /*tp_traverse*/ - __pyx_tp_clear_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr, /*tp_clear*/ + __pyx_tp_traverse_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams, /*tp_traverse*/ + __pyx_tp_clear_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ @@ -3491,7 +4228,7 @@ static PyTypeObject __pyx_type_11fuzzysearch_15_generic_search___pyx_scope_struc 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr, /*tp_new*/ + __pyx_tp_new_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -3546,6 +4283,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1}, {&__pyx_n_s_binary_type, __pyx_k_binary_type, sizeof(__pyx_k_binary_type), 0, 0, 1, 1}, {&__pyx_n_s_c_find_near_matches_generic_line, __pyx_k_c_find_near_matches_generic_line, sizeof(__pyx_k_c_find_near_matches_generic_line), 0, 0, 1, 1}, + {&__pyx_n_s_c_find_near_matches_generic_ngra, __pyx_k_c_find_near_matches_generic_ngra, sizeof(__pyx_k_c_find_near_matches_generic_ngra), 0, 0, 1, 1}, {&__pyx_n_s_c_max_deletions, __pyx_k_c_max_deletions, sizeof(__pyx_k_c_max_deletions), 0, 0, 1, 1}, {&__pyx_n_s_c_max_insertions, __pyx_k_c_max_insertions, sizeof(__pyx_k_c_max_insertions), 0, 0, 1, 1}, {&__pyx_n_s_c_max_l_dist, __pyx_k_c_max_l_dist, sizeof(__pyx_k_c_max_l_dist), 0, 0, 1, 1}, @@ -3556,19 +4294,21 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_candidates, __pyx_k_candidates, sizeof(__pyx_k_candidates), 0, 0, 1, 1}, {&__pyx_n_s_char, __pyx_k_char, sizeof(__pyx_k_char), 0, 0, 1, 1}, {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1}, + {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 0, 0, 1, 1}, {&__pyx_n_s_fuzzysearch__generic_search, __pyx_k_fuzzysearch__generic_search, sizeof(__pyx_k_fuzzysearch__generic_search), 0, 0, 1, 1}, {&__pyx_n_s_fuzzysearch_common, __pyx_k_fuzzysearch_common, sizeof(__pyx_k_fuzzysearch_common), 0, 0, 1, 1}, - {&__pyx_n_s_genexpr, __pyx_k_genexpr, sizeof(__pyx_k_genexpr), 0, 0, 1, 1}, {&__pyx_n_s_have_realloced, __pyx_k_have_realloced, sizeof(__pyx_k_have_realloced), 0, 0, 1, 1}, {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, {&__pyx_n_s_index, __pyx_k_index, sizeof(__pyx_k_index), 0, 0, 1, 1}, {&__pyx_n_s_l_dist, __pyx_k_l_dist, sizeof(__pyx_k_l_dist), 0, 0, 1, 1}, {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, + {&__pyx_n_s_match, __pyx_k_match, sizeof(__pyx_k_match), 0, 0, 1, 1}, + {&__pyx_n_s_match_ptr, __pyx_k_match_ptr, sizeof(__pyx_k_match_ptr), 0, 0, 1, 1}, {&__pyx_n_s_max_deletions, __pyx_k_max_deletions, sizeof(__pyx_k_max_deletions), 0, 0, 1, 1}, {&__pyx_n_s_max_insertions, __pyx_k_max_insertions, sizeof(__pyx_k_max_insertions), 0, 0, 1, 1}, {&__pyx_n_s_max_l_dist, __pyx_k_max_l_dist, sizeof(__pyx_k_max_l_dist), 0, 0, 1, 1}, {&__pyx_n_s_max_substitutions, __pyx_k_max_substitutions, sizeof(__pyx_k_max_substitutions), 0, 0, 1, 1}, - {&__pyx_n_s_maxes_sum, __pyx_k_maxes_sum, sizeof(__pyx_k_maxes_sum), 0, 0, 1, 1}, + {&__pyx_n_s_maxint, __pyx_k_maxint, sizeof(__pyx_k_maxint), 0, 0, 1, 1}, {&__pyx_n_s_n_cand, __pyx_k_n_cand, sizeof(__pyx_k_n_cand), 0, 0, 1, 1}, {&__pyx_n_s_n_candidates, __pyx_k_n_candidates, sizeof(__pyx_k_n_candidates), 0, 0, 1, 1}, {&__pyx_n_s_n_dels, __pyx_k_n_dels, sizeof(__pyx_k_n_dels), 0, 0, 1, 1}, @@ -3577,35 +4317,40 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_n_skipped, __pyx_k_n_skipped, sizeof(__pyx_k_n_skipped), 0, 0, 1, 1}, {&__pyx_n_s_n_subs, __pyx_k_n_subs, sizeof(__pyx_k_n_subs), 0, 0, 1, 1}, {&__pyx_n_s_new_candidates, __pyx_k_new_candidates, sizeof(__pyx_k_new_candidates), 0, 0, 1, 1}, + {&__pyx_n_s_ngram_len, __pyx_k_ngram_len, sizeof(__pyx_k_ngram_len), 0, 0, 1, 1}, + {&__pyx_n_s_ngram_start, __pyx_k_ngram_start, sizeof(__pyx_k_ngram_start), 0, 0, 1, 1}, + {&__pyx_n_s_ngram_str, __pyx_k_ngram_str, sizeof(__pyx_k_ngram_str), 0, 0, 1, 1}, {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1}, + {&__pyx_n_s_replace, __pyx_k_replace, sizeof(__pyx_k_replace), 0, 0, 1, 1}, {&__pyx_n_s_send, __pyx_k_send, sizeof(__pyx_k_send), 0, 0, 1, 1}, + {&__pyx_n_s_seq_len, __pyx_k_seq_len, sizeof(__pyx_k_seq_len), 0, 0, 1, 1}, {&__pyx_n_s_sequence, __pyx_k_sequence, sizeof(__pyx_k_sequence), 0, 0, 1, 1}, {&__pyx_kp_s_sequence_is_of_invalid_type_s, __pyx_k_sequence_is_of_invalid_type_s, sizeof(__pyx_k_sequence_is_of_invalid_type_s), 0, 0, 1, 0}, {&__pyx_n_s_six, __pyx_k_six, sizeof(__pyx_k_six), 0, 0, 1, 1}, + {&__pyx_n_s_small_search_start_index, __pyx_k_small_search_start_index, sizeof(__pyx_k_small_search_start_index), 0, 0, 1, 1}, {&__pyx_n_s_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 0, 1, 1}, {&__pyx_n_s_subseq_index, __pyx_k_subseq_index, sizeof(__pyx_k_subseq_index), 0, 0, 1, 1}, {&__pyx_n_s_subseq_len, __pyx_k_subseq_len, sizeof(__pyx_k_subseq_len), 0, 0, 1, 1}, {&__pyx_n_s_subseq_len_minus_one, __pyx_k_subseq_len_minus_one, sizeof(__pyx_k_subseq_len_minus_one), 0, 0, 1, 1}, {&__pyx_n_s_subsequence, __pyx_k_subsequence, sizeof(__pyx_k_subsequence), 0, 0, 1, 1}, {&__pyx_kp_s_subsequence_is_of_invalid_type_s, __pyx_k_subsequence_is_of_invalid_type_s, sizeof(__pyx_k_subsequence_is_of_invalid_type_s), 0, 0, 1, 0}, - {&__pyx_n_s_sum, __pyx_k_sum, sizeof(__pyx_k_sum), 0, 0, 1, 1}, {&__pyx_n_s_sys, __pyx_k_sys, sizeof(__pyx_k_sys), 0, 0, 1, 1}, {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, + {&__pyx_kp_s_the_subsequence_length_must_be_g, __pyx_k_the_subsequence_length_must_be_g, sizeof(__pyx_k_the_subsequence_length_must_be_g), 0, 0, 1, 0}, {&__pyx_n_s_throw, __pyx_k_throw, sizeof(__pyx_k_throw), 0, 0, 1, 1}, {&__pyx_n_s_tmp, __pyx_k_tmp, sizeof(__pyx_k_tmp), 0, 0, 1, 1}, {&__pyx_n_s_xrange, __pyx_k_xrange, sizeof(__pyx_k_xrange), 0, 0, 1, 1}, {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_ImportError = __Pyx_GetBuiltinName(__pyx_n_s_ImportError); if (!__pyx_builtin_ImportError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_sum = __Pyx_GetBuiltinName(__pyx_n_s_sum); if (!__pyx_builtin_sum) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_ImportError = __Pyx_GetBuiltinName(__pyx_n_s_ImportError); if (!__pyx_builtin_ImportError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #if PY_MAJOR_VERSION >= 3 - __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #else - __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_xrange); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_xrange = __Pyx_GetBuiltinName(__pyx_n_s_xrange); if (!__pyx_builtin_xrange) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} #endif return 0; __pyx_L1_error:; @@ -3616,28 +4361,62 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "fuzzysearch/_generic_search.pyx":44 + /* "fuzzysearch/_generic_search.pyx":45 * * if not subsequence: * raise ValueError('Given subsequence is empty!') # <<<<<<<<<<<<<< * * # optimization: prepare some often used things in advance */ - __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_Given_subsequence_is_empty); if (unlikely(!__pyx_tuple_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_Given_subsequence_is_empty); if (unlikely(!__pyx_tuple_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_tuple_); __Pyx_GIVEREF(__pyx_tuple_); - /* "fuzzysearch/_generic_search.pyx":23 + /* "fuzzysearch/_generic_search.pyx":242 + * + * if not subsequence: + * raise ValueError('Given subsequence is empty!') # <<<<<<<<<<<<<< + * + * # optimization: prepare some often used things in advance + */ + __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_Given_subsequence_is_empty); if (unlikely(!__pyx_tuple__2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 242; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__2); + __Pyx_GIVEREF(__pyx_tuple__2); + + /* "fuzzysearch/_generic_search.pyx":265 + * cdef size_t ngram_len = _subseq_len // (c_max_l_dist + 1) + * if ngram_len == 0: + * raise ValueError('the subsequence length must be greater than max_l_dist') # <<<<<<<<<<<<<< + * + * ngram_str = malloc((ngram_len + 1) * sizeof(char)) + */ + __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_the_subsequence_length_must_be_g); if (unlikely(!__pyx_tuple__3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 265; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__3); + __Pyx_GIVEREF(__pyx_tuple__3); + + /* "fuzzysearch/_generic_search.pyx":24 * * * def c_find_near_matches_generic_linear_programming(subsequence, sequence, # <<<<<<<<<<<<<< * max_substitutions, * max_insertions, */ - __pyx_tuple__2 = PyTuple_Pack(29, __pyx_n_s_subsequence, __pyx_n_s_sequence, __pyx_n_s_max_substitutions, __pyx_n_s_max_insertions, __pyx_n_s_max_deletions, __pyx_n_s_max_l_dist, __pyx_n_s_subseq_len, __pyx_n_s_subseq_len_minus_one, __pyx_n_s_maxes_sum, __pyx_n_s_c_max_l_dist, __pyx_n_s_c_max_substitutions, __pyx_n_s_c_max_insertions, __pyx_n_s_c_max_deletions, __pyx_n_s_alloc_size, __pyx_n_s_candidates, __pyx_n_s_new_candidates, __pyx_n_s_tmp, __pyx_n_s_cand, __pyx_n_s_n_candidates, __pyx_n_s_n_new_candidates, __pyx_n_s_n_cand, __pyx_n_s_c_sequence, __pyx_n_s_c_subsequence, __pyx_n_s_char, __pyx_n_s_index, __pyx_n_s_have_realloced, __pyx_n_s_n_skipped, __pyx_n_s_genexpr, __pyx_n_s_genexpr); if (unlikely(!__pyx_tuple__2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_tuple__2); - __Pyx_GIVEREF(__pyx_tuple__2); - __pyx_codeobj__3 = (PyObject*)__Pyx_PyCode_New(6, 0, 29, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__2, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_Users_taleinat_dev_fuzzysearch, __pyx_n_s_c_find_near_matches_generic_line, 23, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_tuple__4 = PyTuple_Pack(26, __pyx_n_s_subsequence, __pyx_n_s_sequence, __pyx_n_s_max_substitutions, __pyx_n_s_max_insertions, __pyx_n_s_max_deletions, __pyx_n_s_max_l_dist, __pyx_n_s_subseq_len, __pyx_n_s_subseq_len_minus_one, __pyx_n_s_c_max_substitutions, __pyx_n_s_c_max_insertions, __pyx_n_s_c_max_deletions, __pyx_n_s_c_max_l_dist, __pyx_n_s_alloc_size, __pyx_n_s_candidates, __pyx_n_s_new_candidates, __pyx_n_s_tmp, __pyx_n_s_cand, __pyx_n_s_n_candidates, __pyx_n_s_n_new_candidates, __pyx_n_s_n_cand, __pyx_n_s_c_sequence, __pyx_n_s_c_subsequence, __pyx_n_s_char, __pyx_n_s_index, __pyx_n_s_have_realloced, __pyx_n_s_n_skipped); if (unlikely(!__pyx_tuple__4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__4); + __Pyx_GIVEREF(__pyx_tuple__4); + __pyx_codeobj__5 = (PyObject*)__Pyx_PyCode_New(6, 0, 26, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__4, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_Users_taleinat_dev_fuzzysearch, __pyx_n_s_c_find_near_matches_generic_line, 24, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "fuzzysearch/_generic_search.pyx":223 + * + * + * def c_find_near_matches_generic_ngrams(subsequence, sequence, # <<<<<<<<<<<<<< + * max_substitutions, max_insertions, + * max_deletions, max_l_dist=None): + */ + __pyx_tuple__6 = PyTuple_Pack(22, __pyx_n_s_subsequence, __pyx_n_s_sequence, __pyx_n_s_max_substitutions, __pyx_n_s_max_insertions, __pyx_n_s_max_deletions, __pyx_n_s_max_l_dist, __pyx_n_s_subseq_len, __pyx_n_s_subseq_len_minus_one, __pyx_n_s_seq_len, __pyx_n_s_c_max_substitutions, __pyx_n_s_c_max_insertions, __pyx_n_s_c_max_deletions, __pyx_n_s_c_max_l_dist, __pyx_n_s_c_sequence, __pyx_n_s_c_subsequence, __pyx_n_s_ngram_str, __pyx_n_s_ngram_len, __pyx_n_s_index, __pyx_n_s_ngram_start, __pyx_n_s_small_search_start_index, __pyx_n_s_match_ptr, __pyx_n_s_match); if (unlikely(!__pyx_tuple__6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_tuple__6); + __Pyx_GIVEREF(__pyx_tuple__6); + __pyx_codeobj__7 = (PyObject*)__Pyx_PyCode_New(6, 0, 22, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__6, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_Users_taleinat_dev_fuzzysearch, __pyx_n_s_c_find_near_matches_generic_ngra, 223, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -3649,7 +4428,7 @@ static int __Pyx_InitGlobals(void) { if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;}; __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_int_536870912 = PyInt_FromLong(536870912L); if (unlikely(!__pyx_int_536870912)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; __pyx_L1_error:; return -1; @@ -3741,98 +4520,107 @@ PyMODINIT_FUNC PyInit__generic_search(void) /*--- Variable export code ---*/ /*--- Function export code ---*/ /*--- Type init code ---*/ - if (PyType_Ready(&__pyx_type_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_type_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming.tp_print = 0; __pyx_ptype_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming = &__pyx_type_11fuzzysearch_15_generic_search___pyx_scope_struct__c_find_near_matches_generic_linear_programming; - if (PyType_Ready(&__pyx_type_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_type_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr.tp_print = 0; - __pyx_ptype_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr = &__pyx_type_11fuzzysearch_15_generic_search___pyx_scope_struct_1_genexpr; + if (PyType_Ready(&__pyx_type_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_type_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams.tp_print = 0; + __pyx_ptype_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams = &__pyx_type_11fuzzysearch_15_generic_search___pyx_scope_struct_1_c_find_near_matches_generic_ngrams; /*--- Type import code ---*/ /*--- Variable import code ---*/ /*--- Function import code ---*/ /*--- Execution code ---*/ /* "fuzzysearch/_generic_search.pyx":1 - * import sys # <<<<<<<<<<<<<< + * from sys import maxint # <<<<<<<<<<<<<< * import six * from fuzzysearch.common import Match */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_sys, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_n_s_maxint); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_maxint); + __Pyx_GIVEREF(__pyx_n_s_maxint); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_sys, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_maxint); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_maxint, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "fuzzysearch/_generic_search.pyx":2 - * import sys + * from sys import maxint * import six # <<<<<<<<<<<<<< * from fuzzysearch.common import Match * from libc.stdlib cimport malloc, free, realloc */ - __pyx_t_1 = __Pyx_Import(__pyx_n_s_six, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_six, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_2 = __Pyx_Import(__pyx_n_s_six, 0, -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_six, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "fuzzysearch/_generic_search.pyx":3 - * import sys + * from sys import maxint * import six * from fuzzysearch.common import Match # <<<<<<<<<<<<<< * from libc.stdlib cimport malloc, free, realloc - * + * from libc.string cimport strstr, strncpy */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_n_s_Match); - PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_Match); - __Pyx_GIVEREF(__pyx_n_s_Match); - __pyx_t_2 = __Pyx_Import(__pyx_n_s_fuzzysearch_common, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_Match); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_n_s_Match); + PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_Match); + __Pyx_GIVEREF(__pyx_n_s_Match); + __pyx_t_1 = __Pyx_Import(__pyx_n_s_fuzzysearch_common, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_Match, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_Match); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_Match, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "fuzzysearch/_generic_search.pyx":7 + /* "fuzzysearch/_generic_search.pyx":8 * * * __all__ = ['c_find_near_matches_generic_linear_programming'] # <<<<<<<<<<<<<< * * */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_n_s_c_find_near_matches_generic_line); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_c_find_near_matches_generic_line); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_c_find_near_matches_generic_line); __Pyx_GIVEREF(__pyx_n_s_c_find_near_matches_generic_line); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "fuzzysearch/_generic_search.pyx":14 + /* "fuzzysearch/_generic_search.pyx":15 * * * ALLOWED_TYPES = (six.binary_type, bytearray) # <<<<<<<<<<<<<< * try: * from Bio.Seq import Seq */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_six); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_binary_type); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_six); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_binary_type); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)((PyObject*)(&PyByteArray_Type)))); - PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)((PyObject*)(&PyByteArray_Type)))); + PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)((PyObject*)(&PyByteArray_Type)))); __Pyx_GIVEREF(((PyObject *)((PyObject*)(&PyByteArray_Type)))); - __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_ALLOWED_TYPES, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 14; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_ALLOWED_TYPES, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "fuzzysearch/_generic_search.pyx":15 + /* "fuzzysearch/_generic_search.pyx":16 * * ALLOWED_TYPES = (six.binary_type, bytearray) * try: # <<<<<<<<<<<<<< @@ -3846,61 +4634,61 @@ PyMODINIT_FUNC PyInit__generic_search(void) __Pyx_XGOTREF(__pyx_t_5); /*try:*/ { - /* "fuzzysearch/_generic_search.pyx":16 + /* "fuzzysearch/_generic_search.pyx":17 * ALLOWED_TYPES = (six.binary_type, bytearray) * try: * from Bio.Seq import Seq # <<<<<<<<<<<<<< * except ImportError: * pass */ - __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L2_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_INCREF(__pyx_n_s_Seq); - PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_Seq); - __Pyx_GIVEREF(__pyx_n_s_Seq); - __pyx_t_1 = __Pyx_Import(__pyx_n_s_Bio_Seq, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L2_error;} + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L2_error;} __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_Seq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L2_error;} + __Pyx_INCREF(__pyx_n_s_Seq); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_Seq); + __Pyx_GIVEREF(__pyx_n_s_Seq); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_Bio_Seq, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L2_error;} __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_Seq, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; __pyx_clineno = __LINE__; goto __pyx_L2_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_Seq); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L2_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_Seq, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L2_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } /*else:*/ { - /* "fuzzysearch/_generic_search.pyx":20 + /* "fuzzysearch/_generic_search.pyx":21 * pass * else: * ALLOWED_TYPES += (Seq,) # <<<<<<<<<<<<<< * * */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_ALLOWED_TYPES); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L4_except_error;} + __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_ALLOWED_TYPES); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L4_except_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_Seq); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L4_except_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_Seq); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L4_except_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L4_except_error;} + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L4_except_error;} __Pyx_GOTREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L4_except_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - if (PyDict_SetItem(__pyx_d, __pyx_n_s_ALLOWED_TYPES, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L4_except_error;} + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L4_except_error;} + __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (PyDict_SetItem(__pyx_d, __pyx_n_s_ALLOWED_TYPES, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L4_except_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L9_try_end; __pyx_L2_error:; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "fuzzysearch/_generic_search.pyx":17 + /* "fuzzysearch/_generic_search.pyx":18 * try: * from Bio.Seq import Seq * except ImportError: # <<<<<<<<<<<<<< @@ -3927,27 +4715,39 @@ PyMODINIT_FUNC PyInit__generic_search(void) __pyx_L9_try_end:; } - /* "fuzzysearch/_generic_search.pyx":23 + /* "fuzzysearch/_generic_search.pyx":24 * * * def c_find_near_matches_generic_linear_programming(subsequence, sequence, # <<<<<<<<<<<<<< * max_substitutions, * max_insertions, */ - __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_11fuzzysearch_15_generic_search_1c_find_near_matches_generic_linear_programming, NULL, __pyx_n_s_fuzzysearch__generic_search); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_c_find_near_matches_generic_line, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_11fuzzysearch_15_generic_search_1c_find_near_matches_generic_linear_programming, NULL, __pyx_n_s_fuzzysearch__generic_search); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_c_find_near_matches_generic_line, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "fuzzysearch/_generic_search.pyx":223 + * + * + * def c_find_near_matches_generic_ngrams(subsequence, sequence, # <<<<<<<<<<<<<< + * max_substitutions, max_insertions, + * max_deletions, max_l_dist=None): + */ + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_11fuzzysearch_15_generic_search_4c_find_near_matches_generic_ngrams, NULL, __pyx_n_s_fuzzysearch__generic_search); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_c_find_near_matches_generic_ngra, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "fuzzysearch/_generic_search.pyx":1 - * import sys # <<<<<<<<<<<<<< + * from sys import maxint # <<<<<<<<<<<<<< * import six * from fuzzysearch.common import Match */ - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); @@ -4137,10 +4937,6 @@ bad: return -1; } -static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname) { - PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname); -} - static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) { PyObject *result; #if CYTHON_COMPILING_IN_CPYTHON @@ -4484,6 +5280,103 @@ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb) #endif } +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice( + PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop, + PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice, + int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) { +#if CYTHON_COMPILING_IN_CPYTHON + PyMappingMethods* mp; +#if PY_MAJOR_VERSION < 3 + PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence; + if (likely(ms && ms->sq_slice)) { + if (!has_cstart) { + if (_py_start && (*_py_start != Py_None)) { + cstart = __Pyx_PyIndex_AsSsize_t(*_py_start); + if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad; + } else + cstart = 0; + } + if (!has_cstop) { + if (_py_stop && (*_py_stop != Py_None)) { + cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop); + if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad; + } else + cstop = PY_SSIZE_T_MAX; + } + if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) { + Py_ssize_t l = ms->sq_length(obj); + if (likely(l >= 0)) { + if (cstop < 0) { + cstop += l; + if (cstop < 0) cstop = 0; + } + if (cstart < 0) { + cstart += l; + if (cstart < 0) cstart = 0; + } + } else { + if (PyErr_ExceptionMatches(PyExc_OverflowError)) + PyErr_Clear(); + else + goto bad; + } + } + return ms->sq_slice(obj, cstart, cstop); + } +#endif + mp = Py_TYPE(obj)->tp_as_mapping; + if (likely(mp && mp->mp_subscript)) +#endif + { + PyObject* result; + PyObject *py_slice, *py_start, *py_stop; + if (_py_slice) { + py_slice = *_py_slice; + } else { + PyObject* owned_start = NULL; + PyObject* owned_stop = NULL; + if (_py_start) { + py_start = *_py_start; + } else { + if (has_cstart) { + owned_start = py_start = PyInt_FromSsize_t(cstart); + if (unlikely(!py_start)) goto bad; + } else + py_start = Py_None; + } + if (_py_stop) { + py_stop = *_py_stop; + } else { + if (has_cstop) { + owned_stop = py_stop = PyInt_FromSsize_t(cstop); + if (unlikely(!py_stop)) { + Py_XDECREF(owned_start); + goto bad; + } + } else + py_stop = Py_None; + } + py_slice = PySlice_New(py_start, py_stop, Py_None); + Py_XDECREF(owned_start); + Py_XDECREF(owned_stop); + if (unlikely(!py_slice)) goto bad; + } +#if CYTHON_COMPILING_IN_CPYTHON + result = mp->mp_subscript(obj, py_slice); +#else + result = PyObject_GetItem(obj, py_slice); +#endif + if (!_py_slice) { + Py_DECREF(py_slice); + } + return result; + } + PyErr_Format(PyExc_TypeError, + "'%.200s' object is unsliceable", Py_TYPE(obj)->tp_name); +bad: + return NULL; +} + static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) { PyObject* value = __Pyx_PyObject_GetAttrStr(module, name); if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) { @@ -4579,32 +5472,6 @@ bad: return module; } -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { - const long neg_one = (long) -1, const_zero = 0; - const int is_unsigned = neg_one > const_zero; - if (is_unsigned) { - if (sizeof(long) < sizeof(long)) { - return PyInt_FromLong((long) value); - } else if (sizeof(long) <= sizeof(unsigned long)) { - return PyLong_FromUnsignedLong((unsigned long) value); - } else if (sizeof(long) <= sizeof(unsigned long long)) { - return PyLong_FromUnsignedLongLong((unsigned long long) value); - } - } else { - if (sizeof(long) <= sizeof(long)) { - return PyInt_FromLong((long) value); - } else if (sizeof(long) <= sizeof(long long)) { - return PyLong_FromLongLong((long long) value); - } - } - { - int one = 1; int little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&value; - return _PyLong_FromByteArray(bytes, sizeof(long), - little, !is_unsigned); - } -} - #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func) \ { \ func_type value = func(x); \ @@ -4626,21 +5493,21 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { #include "longintrepr.h" #endif #endif -static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) { - const size_t neg_one = (size_t) -1, const_zero = 0; +static CYTHON_INLINE unsigned int __Pyx_PyInt_As_unsigned_int(PyObject *x) { + const unsigned int neg_one = (unsigned int) -1, const_zero = 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { - if (sizeof(size_t) < sizeof(long)) { - __PYX_VERIFY_RETURN_INT(size_t, long, PyInt_AS_LONG) + if (sizeof(unsigned int) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(unsigned int, long, PyInt_AS_LONG) } else { long val = PyInt_AS_LONG(x); if (is_unsigned && unlikely(val < 0)) { PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to size_t"); - return (size_t) -1; + "can't convert negative value to unsigned int"); + return (unsigned int) -1; } - return (size_t) val; + return (unsigned int) val; } } else #endif @@ -4648,40 +5515,40 @@ static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) { if (is_unsigned) { #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 #if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(size_t)) { + if (sizeof(digit) <= sizeof(unsigned int)) { switch (Py_SIZE(x)) { case 0: return 0; - case 1: return (size_t) ((PyLongObject*)x)->ob_digit[0]; + case 1: return (unsigned int) ((PyLongObject*)x)->ob_digit[0]; } } #endif #endif if (unlikely(Py_SIZE(x) < 0)) { PyErr_SetString(PyExc_OverflowError, - "can't convert negative value to size_t"); - return (size_t) -1; + "can't convert negative value to unsigned int"); + return (unsigned int) -1; } - if (sizeof(size_t) <= sizeof(unsigned long)) { - __PYX_VERIFY_RETURN_INT(size_t, unsigned long, PyLong_AsUnsignedLong) - } else if (sizeof(size_t) <= sizeof(unsigned long long)) { - __PYX_VERIFY_RETURN_INT(size_t, unsigned long long, PyLong_AsUnsignedLongLong) + if (sizeof(unsigned int) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long, PyLong_AsUnsignedLong) + } else if (sizeof(unsigned int) <= sizeof(unsigned long long)) { + __PYX_VERIFY_RETURN_INT(unsigned int, unsigned long long, PyLong_AsUnsignedLongLong) } } else { #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 #if CYTHON_USE_PYLONG_INTERNALS - if (sizeof(digit) <= sizeof(size_t)) { + if (sizeof(digit) <= sizeof(unsigned int)) { switch (Py_SIZE(x)) { case 0: return 0; - case 1: return +(size_t) ((PyLongObject*)x)->ob_digit[0]; - case -1: return -(size_t) ((PyLongObject*)x)->ob_digit[0]; + case 1: return +(unsigned int) ((PyLongObject*)x)->ob_digit[0]; + case -1: return -(unsigned int) ((PyLongObject*)x)->ob_digit[0]; } } #endif #endif - if (sizeof(size_t) <= sizeof(long)) { - __PYX_VERIFY_RETURN_INT(size_t, long, PyLong_AsLong) - } else if (sizeof(size_t) <= sizeof(long long)) { - __PYX_VERIFY_RETURN_INT(size_t, long long, PyLong_AsLongLong) + if (sizeof(unsigned int) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT(unsigned int, long, PyLong_AsLong) + } else if (sizeof(unsigned int) <= sizeof(long long)) { + __PYX_VERIFY_RETURN_INT(unsigned int, long long, PyLong_AsLongLong) } } { @@ -4689,7 +5556,7 @@ static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) { PyErr_SetString(PyExc_RuntimeError, "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); #else - size_t val; + unsigned int val; PyObject *v = __Pyx_PyNumber_Int(x); #if PY_MAJOR_VERSION < 3 if (likely(v) && !PyLong_Check(v)) { @@ -4709,18 +5576,44 @@ static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) { return val; } #endif - return (size_t) -1; + return (unsigned int) -1; } } else { - size_t val; + unsigned int val; PyObject *tmp = __Pyx_PyNumber_Int(x); - if (!tmp) return (size_t) -1; - val = __Pyx_PyInt_As_size_t(tmp); + if (!tmp) return (unsigned int) -1; + val = __Pyx_PyInt_As_unsigned_int(tmp); Py_DECREF(tmp); return val; } } +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_int(unsigned int value) { + const unsigned int neg_one = (unsigned int) -1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(unsigned int) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(unsigned int) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); + } else if (sizeof(unsigned int) <= sizeof(unsigned long long)) { + return PyLong_FromUnsignedLongLong((unsigned long long) value); + } + } else { + if (sizeof(unsigned int) <= sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(unsigned int) <= sizeof(long long)) { + return PyLong_FromLongLong((long long) value); + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(unsigned int), + little, !is_unsigned); + } +} + #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 #if CYTHON_USE_PYLONG_INTERNALS #include "longintrepr.h" @@ -4821,29 +5714,103 @@ static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *x) { } } -static CYTHON_INLINE PyObject* __Pyx_PyInt_From_unsigned_int(unsigned int value) { - const unsigned int neg_one = (unsigned int) -1, const_zero = 0; +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + #include "longintrepr.h" + #endif +#endif +static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) { + const size_t neg_one = (size_t) -1, const_zero = 0; const int is_unsigned = neg_one > const_zero; - if (is_unsigned) { - if (sizeof(unsigned int) < sizeof(long)) { - return PyInt_FromLong((long) value); - } else if (sizeof(unsigned int) <= sizeof(unsigned long)) { - return PyLong_FromUnsignedLong((unsigned long) value); - } else if (sizeof(unsigned int) <= sizeof(unsigned long long)) { - return PyLong_FromUnsignedLongLong((unsigned long long) value); +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if (sizeof(size_t) < sizeof(long)) { + __PYX_VERIFY_RETURN_INT(size_t, long, PyInt_AS_LONG) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to size_t"); + return (size_t) -1; + } + return (size_t) val; + } + } else +#endif + if (likely(PyLong_Check(x))) { + if (is_unsigned) { +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + if (sizeof(digit) <= sizeof(size_t)) { + switch (Py_SIZE(x)) { + case 0: return 0; + case 1: return (size_t) ((PyLongObject*)x)->ob_digit[0]; + } + } + #endif +#endif + if (unlikely(Py_SIZE(x) < 0)) { + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to size_t"); + return (size_t) -1; + } + if (sizeof(size_t) <= sizeof(unsigned long)) { + __PYX_VERIFY_RETURN_INT(size_t, unsigned long, PyLong_AsUnsignedLong) + } else if (sizeof(size_t) <= sizeof(unsigned long long)) { + __PYX_VERIFY_RETURN_INT(size_t, unsigned long long, PyLong_AsUnsignedLongLong) + } + } else { +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_USE_PYLONG_INTERNALS + if (sizeof(digit) <= sizeof(size_t)) { + switch (Py_SIZE(x)) { + case 0: return 0; + case 1: return +(size_t) ((PyLongObject*)x)->ob_digit[0]; + case -1: return -(size_t) ((PyLongObject*)x)->ob_digit[0]; + } + } + #endif +#endif + if (sizeof(size_t) <= sizeof(long)) { + __PYX_VERIFY_RETURN_INT(size_t, long, PyLong_AsLong) + } else if (sizeof(size_t) <= sizeof(long long)) { + __PYX_VERIFY_RETURN_INT(size_t, long long, PyLong_AsLongLong) + } + } + { +#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray) + PyErr_SetString(PyExc_RuntimeError, + "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers"); +#else + size_t val; + PyObject *v = __Pyx_PyNumber_Int(x); + #if PY_MAJOR_VERSION < 3 + if (likely(v) && !PyLong_Check(v)) { + PyObject *tmp = v; + v = PyNumber_Long(tmp); + Py_DECREF(tmp); + } + #endif + if (likely(v)) { + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + int ret = _PyLong_AsByteArray((PyLongObject *)v, + bytes, sizeof(val), + is_little, !is_unsigned); + Py_DECREF(v); + if (likely(!ret)) + return val; + } +#endif + return (size_t) -1; } } else { - if (sizeof(unsigned int) <= sizeof(long)) { - return PyInt_FromLong((long) value); - } else if (sizeof(unsigned int) <= sizeof(long long)) { - return PyLong_FromLongLong((long long) value); - } - } - { - int one = 1; int little = (int)*(unsigned char *)&one; - unsigned char *bytes = (unsigned char *)&value; - return _PyLong_FromByteArray(bytes, sizeof(unsigned int), - little, !is_unsigned); + size_t val; + PyObject *tmp = __Pyx_PyNumber_Int(x); + if (!tmp) return (size_t) -1; + val = __Pyx_PyInt_As_size_t(tmp); + Py_DECREF(tmp); + return val; } } @@ -4873,6 +5840,32 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { } } +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { + const long neg_one = (long) -1, const_zero = 0; + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(long) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(long) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); + } else if (sizeof(long) <= sizeof(unsigned long long)) { + return PyLong_FromUnsignedLongLong((unsigned long long) value); + } + } else { + if (sizeof(long) <= sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(long) <= sizeof(long long)) { + return PyLong_FromLongLong((long long) value); + } + } + { + int one = 1; int little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&value; + return _PyLong_FromByteArray(bytes, sizeof(long), + little, !is_unsigned); + } +} + #if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 #if CYTHON_USE_PYLONG_INTERNALS #include "longintrepr.h" diff --git a/fuzzysearch/_generic_search.pyx b/fuzzysearch/_generic_search.pyx index ef16a1f..100e918 100644 --- a/fuzzysearch/_generic_search.pyx +++ b/fuzzysearch/_generic_search.pyx @@ -1,6 +1,8 @@ +from sys import maxint import six from fuzzysearch.common import Match from libc.stdlib cimport malloc, free, realloc +from libc.string cimport strstr, strncpy __all__ = ['c_find_near_matches_generic_linear_programming'] @@ -43,29 +45,27 @@ def c_find_near_matches_generic_linear_programming(subsequence, sequence, raise ValueError('Given subsequence is empty!') # optimization: prepare some often used things in advance - cdef int _subseq_len = len(subsequence) - cdef int _subseq_len_minus_one = _subseq_len - 1 + cdef size_t _subseq_len = len(subsequence) + cdef size_t _subseq_len_minus_one = _subseq_len - 1 - maxes_sum = sum( - (x if x is not None else 0) - for x in [max_substitutions, max_insertions, max_deletions] + cdef unsigned int c_max_substitutions = max_substitutions if max_substitutions is not None else (1<<29) + cdef unsigned int c_max_insertions = max_insertions if max_insertions is not None else (1<<29) + cdef unsigned int c_max_deletions = max_deletions if max_deletions is not None else (1<<29) + + # TODO: write a good comment + cdef unsigned int c_max_l_dist = min( + max_l_dist if max_l_dist is not None else (1<<29), + c_max_substitutions + c_max_insertions + c_max_deletions, ) - if max_l_dist is None or max_l_dist >= maxes_sum: - max_l_dist = maxes_sum - cdef c_max_l_dist = max_l_dist - cdef c_max_substitutions = max_substitutions - cdef c_max_insertions = max_insertions - cdef c_max_deletions = max_deletions - - cdef alloc_size + cdef size_t alloc_size cdef GenericSearchCandidate* candidates cdef GenericSearchCandidate* new_candidates cdef GenericSearchCandidate* _tmp cdef GenericSearchCandidate cand - cdef int n_candidates = 0 - cdef int n_new_candidates = 0 - cdef int n_cand + cdef size_t n_candidates = 0 + cdef size_t n_new_candidates = 0 + cdef size_t n_cand cdef char* c_sequence = sequence cdef char* c_subsequence = subsequence @@ -80,7 +80,7 @@ def c_find_near_matches_generic_linear_programming(subsequence, sequence, free(candidates) raise MemoryError() - cdef unsigned int index + cdef size_t index try: index = 0 have_realloced = False @@ -92,7 +92,7 @@ def c_find_near_matches_generic_linear_programming(subsequence, sequence, cand = candidates[n_cand] if n_new_candidates + 4 > alloc_size: - alloc_size += alloc_size // 2 + alloc_size *= 2 _tmp = realloc(new_candidates, alloc_size * sizeof(GenericSearchCandidate)) if _tmp is NULL: raise MemoryError() @@ -218,3 +218,80 @@ def c_find_near_matches_generic_linear_programming(subsequence, sequence, finally: free(candidates) free(new_candidates) + + +def c_find_near_matches_generic_ngrams(subsequence, sequence, + max_substitutions, max_insertions, + max_deletions, max_l_dist=None): + """search for near-matches of subsequence in sequence + + This searches for near-matches, where the nearly-matching parts of the + sequence must meet the following limitations (relative to the subsequence): + + * the maximum allowed number of character substitutions + * the maximum allowed number of new characters inserted + * and the maximum allowed number of character deletions + * the total number of substitutions, insertions and deletions + """ + if not isinstance(sequence, ALLOWED_TYPES): + raise TypeError('sequence is of invalid type %s' % type(subsequence)) + if not isinstance(subsequence, ALLOWED_TYPES): + raise TypeError('subsequence is of invalid type %s' % type(subsequence)) + + if not subsequence: + raise ValueError('Given subsequence is empty!') + + # optimization: prepare some often used things in advance + cdef size_t _subseq_len = len(subsequence) + cdef size_t _subseq_len_minus_one = _subseq_len - 1 + cdef size_t _seq_len = len(sequence) + + cdef unsigned int c_max_substitutions = max_substitutions if max_substitutions is not None else (1<<29) + cdef unsigned int c_max_insertions = max_insertions if max_insertions is not None else (1<<29) + cdef unsigned int c_max_deletions = max_deletions if max_deletions is not None else (1<<29) + + # TODO: write a good comment + cdef unsigned int c_max_l_dist = min( + max_l_dist if max_l_dist is not None else (1<<29), + c_max_substitutions + c_max_insertions + c_max_deletions, + ) + + cdef char* c_sequence = sequence + cdef char* c_subsequence = subsequence + cdef char* ngram_str + + cdef size_t ngram_len = _subseq_len // (c_max_l_dist + 1) + if ngram_len == 0: + raise ValueError('the subsequence length must be greater than max_l_dist') + + ngram_str = malloc((ngram_len + 1) * sizeof(char)) + if ngram_str is NULL: + raise MemoryError() + + cdef int index + cdef size_t ngram_start, small_search_start_index + cdef char *match_ptr + + try: + ngram_str[ngram_len] = 0 + + for ngram_start in xrange(0, _subseq_len - ngram_len + 1, ngram_len): + strncpy(ngram_str, c_subsequence + ngram_start, ngram_len) + + match_ptr = strstr(c_sequence, ngram_str) + while match_ptr != NULL: + index = (match_ptr - c_sequence) + small_search_start_index = max(0, index - (ngram_start + c_max_l_dist)) + # try to expand left and/or right according to n_ngram + for match in c_find_near_matches_generic_linear_programming( + subsequence, sequence[small_search_start_index:index - ngram_start + _subseq_len + c_max_l_dist], + max_substitutions, max_insertions, max_deletions, c_max_l_dist, + ): + yield match._replace( + start=match.start + small_search_start_index, + end=match.end + small_search_start_index, + ) + match_ptr = strstr(match_ptr + 1, ngram_str) + + finally: + free(ngram_str) diff --git a/fuzzysearch/generic_search.py b/fuzzysearch/generic_search.py index df52c9b..4db860b 100644 --- a/fuzzysearch/generic_search.py +++ b/fuzzysearch/generic_search.py @@ -18,11 +18,50 @@ GenericSearchCandidate = namedtuple( ) -def _find_near_matches_generic_linear_programming(subsequence, sequence, - max_substitutions, - max_insertions, - max_deletions, - max_l_dist=None): +def _check_arguments(subsequence, sequence, + max_substitutions, max_insertions, + max_deletions, max_l_dist=None): + if not subsequence: + raise ValueError('Given subsequence is empty!') + + if max_l_dist is None: + if ( + max_substitutions is None or + max_insertions is None or + max_deletions is None + ): + if ( + max_substitutions is None and + max_insertions is None and + max_deletions is None + ): + raise ValueError('No limitations given!') + + if max_substitutions is None: + raise ValueError('# substitutions must be limited!') + if max_insertions is None: + raise ValueError('# insertions must be limited!') + if max_deletions is None: + raise ValueError('# deletions must be limited!') + + +def _get_max_l_dist(max_substitutions, max_insertions, + max_deletions, max_l_dist): + maxes_sum = ( + (max_substitutions if max_substitutions is not None else (1 << 29)) + + (max_insertions if max_insertions is not None else (1 << 29)) + + (max_deletions if max_deletions is not None else (1 << 29)) + ) + return ( + max_l_dist + if max_l_dist is not None and max_l_dist <= maxes_sum + else maxes_sum + ) + + +def find_near_matches_generic(subsequence, sequence, + max_substitutions, max_insertions, + max_deletions, max_l_dist=None): """search for near-matches of subsequence in sequence This searches for near-matches, where the nearly-matching parts of the @@ -33,19 +72,64 @@ def _find_near_matches_generic_linear_programming(subsequence, sequence, * and the maximum allowed number of character deletions * the total number of substitutions, insertions and deletions """ - if not subsequence: - raise ValueError('Given subsequence is empty!') + _check_arguments(subsequence, sequence, max_substitutions, max_insertions, + max_deletions, max_l_dist) + + max_l_dist = _get_max_l_dist(max_substitutions, max_insertions, + max_deletions, max_l_dist) + + # if the limitations are so strict that only exact matches are allowed, + # use search_exact() + if max_l_dist == 0: + return [ + Match(start_index, start_index + len(subsequence), 0) + for start_index in search_exact(subsequence, sequence) + ] + + # if the n-gram length would be at least 3, use the n-gram search method + elif len(subsequence) // (max_l_dist + 1) >= 3: + return find_near_matches_generic_ngrams(subsequence, sequence, + max_substitutions, + max_insertions, + max_deletions, + max_l_dist) + + # use the linear programming search method + else: + matches = find_near_matches_generic_linear_programming( + subsequence, sequence, + max_substitutions, max_insertions, + max_deletions, max_l_dist) + + match_groups = group_matches(matches) + best_matches = [get_best_match_in_group(group) for group in match_groups] + return sorted(best_matches) + + +def _find_near_matches_generic_linear_programming(subsequence, sequence, + max_substitutions, + max_insertions, + max_deletions, + max_l_dist=None): + """search for near-matches of subsequence in sequence + + This searches for near-matches, where the nearly-matching parts of the + sequence must meet the following limitations (relative to the subsequence): + + * the maximum allowed number of character substitutions + * the maximum allowed number of new characters inserted + * and the maximum allowed number of character deletions + * the total number of substitutions, insertions and deletions + """ + _check_arguments(subsequence, sequence, max_substitutions, max_insertions, + max_deletions, max_l_dist) + + max_l_dist = _get_max_l_dist(max_substitutions, max_insertions, + max_deletions, max_l_dist) # optimization: prepare some often used things in advance _subseq_len = len(subsequence) - maxes_sum = sum( - (x if x is not None else 0) - for x in [max_substitutions, max_insertions, max_deletions] - ) - if max_l_dist is None or max_l_dist >= maxes_sum: - max_l_dist = maxes_sum - candidates = [] for index, char in enumerate(sequence): candidates.append(GenericSearchCandidate(index, 0, 0, 0, 0, 0)) @@ -179,13 +263,12 @@ def find_near_matches_generic_ngrams(subsequence, sequence, * and the maximum allowed number of character deletions * the total number of substitutions, insertions and deletions """ - maxes_sum = ( - (max_substitutions if max_substitutions is not None else 0) + - (max_insertions if max_insertions is not None else 0) + - (max_deletions if max_deletions is not None else 0) - ) - if max_l_dist is None or max_l_dist >= maxes_sum: - max_l_dist = maxes_sum + _check_arguments(subsequence, sequence, + max_substitutions, max_insertions, + max_deletions, max_l_dist) + + max_l_dist = _get_max_l_dist(max_substitutions, max_insertions, + max_deletions, max_l_dist) matches = list(_find_near_matches_generic_ngrams(subsequence, sequence, max_substitutions, @@ -244,13 +327,12 @@ def has_near_match_generic_ngrams(subsequence, sequence, * and the maximum allowed number of character deletions * the total number of substitutions, insertions and deletions """ - maxes_sum = ( - (max_substitutions if max_substitutions is not None else 0) + - (max_insertions if max_insertions is not None else 0) + - (max_deletions if max_deletions is not None else 0) - ) - if max_l_dist is None or max_l_dist >= maxes_sum: - max_l_dist = maxes_sum + _check_arguments(subsequence, sequence, + max_substitutions, max_insertions, + max_deletions, max_l_dist) + + max_l_dist = _get_max_l_dist(max_substitutions, max_insertions, + max_deletions, max_l_dist) for match in _find_near_matches_generic_ngrams(subsequence, sequence, max_substitutions, diff --git a/tests/test_find_near_matches.py b/tests/test_find_near_matches.py index 8e9e545..82087df 100644 --- a/tests/test_find_near_matches.py +++ b/tests/test_find_near_matches.py @@ -28,7 +28,7 @@ class TestFindNearMatches(unittest.TestCase): MockFunctionFailsUnlessDefined() self.mock_find_near_matches_substitutions = \ MockFunctionFailsUnlessDefined() - self.mock_find_near_matches_generic_linear_programming = \ + self.mock_find_near_matches_generic = \ MockFunctionFailsUnlessDefined() patcher = mock.patch.multiple( @@ -38,8 +38,8 @@ class TestFindNearMatches(unittest.TestCase): self.mock_find_near_matches_levenshtein, find_near_matches_substitutions= self.mock_find_near_matches_substitutions, - find_near_matches_generic_linear_programming= - self.mock_find_near_matches_generic_linear_programming, + find_near_matches_generic= + self.mock_find_near_matches_generic, ) self.addCleanup(patcher.stop) patcher.start() @@ -154,14 +154,14 @@ class TestFindNearMatches(unittest.TestCase): ) def test_generic(self): - self.mock_find_near_matches_generic_linear_programming.return_value = [42] + self.mock_find_near_matches_generic.return_value = [42] self.assertEqual( find_near_matches('a', 'a', 1, 1, 1), [42], ) self.assertEqual( - self.mock_find_near_matches_generic_linear_programming.call_count, + self.mock_find_near_matches_generic.call_count, 1, ) @@ -170,6 +170,6 @@ class TestFindNearMatches(unittest.TestCase): [42], ) self.assertEqual( - self.mock_find_near_matches_generic_linear_programming.call_count, + self.mock_find_near_matches_generic.call_count, 2, ) diff --git a/tests/test_generic_search.py b/tests/test_generic_search.py index 1510726..e3c7205 100644 --- a/tests/test_generic_search.py +++ b/tests/test_generic_search.py @@ -9,7 +9,7 @@ from fuzzysearch.generic_search import \ has_near_match_generic_ngrams as hnm_generic_ngrams -class TestGenericSearchLPAsLevenshtein(TestFindNearMatchesLevenshteinBase, +class TestGenericSearchLpAsLevenshtein(TestFindNearMatchesLevenshteinBase, unittest.TestCase): def search(self, subsequence, sequence, max_l_dist): return [ @@ -28,7 +28,7 @@ class TestGenericSearchNgramsAsLevenshtein(TestFindNearMatchesLevenshteinBase, max_l_dist, max_l_dist, max_l_dist) -class TestGenericSearchLPAsSubstitutionsOnly(TestSubstitionsOnlyBase, +class TestGenericSearchLpAsSubstitutionsOnly(TestSubstitionsOnlyBase, unittest.TestCase): def search(self, subsequence, sequence, max_subs): return list( @@ -90,11 +90,6 @@ class TestGenericSearchBase(object): [Match(start=4, end=7, dist=0)], ) - self.assertListEqual( - self.search('def', 'abcddefg', 0, 1, 0), - [Match(start=3, end=7, dist=1), Match(start=4, end=7, dist=0)], - ) - self.assertIn( Match(start=4, end=7, dist=0), self.search('def', 'abcddefg', 0, 0, 1), @@ -129,6 +124,70 @@ class TestGenericSearchBase(object): [Match(start=3, end=5, dist=1)], ) + def test_valid_none_arguments(self): + # check that no exception is raised when some values are None + self.assertEqual( + self.search('a', 'b', 0, None, None, 0), + [], + ) + + self.assertEqual( + self.search('a', 'b', None, 0, None, 0), + [], + ) + + self.assertEqual( + self.search('a', 'b', None, None, 0, 0), + [], + ) + + self.assertEqual( + self.search('a', 'b', 0, 0, None, 0), + [], + ) + + self.assertEqual( + self.search('a', 'b', 0, None, 0, 0), + [], + ) + + self.assertEqual( + self.search('a', 'b', None, 0, 0, 0), + [], + ) + + self.assertEqual( + self.search('a', 'b', None, None, None, 0), + [], + ) + + self.assertEqual( + self.search('a', 'b', 0, 0, 0, None), + [], + ) + + def test_invalid_none_arguments(self): + # check that an exception is raised when max_l_dist is None as well as + # at least one other limitation + with self.assertRaises(ValueError): + self.search('a', 'b', None, None, None, None) + + +class TestGenericSearchLp(TestGenericSearchBase, unittest.TestCase): + def search(self, pattern, sequence, max_subs, max_ins, max_dels, + max_l_dist=None): + return list(fnm_generic_lp(pattern, sequence, + max_subs, max_ins, max_dels, max_l_dist)) + + def test_double_first_item_two_results(self): + # sequence = 'abcdefg' + # pattern = 'bde' + self.assertListEqual( + self.search('def', 'abcddefg', 0, 1, 0), + [Match(start=3, end=7, dist=1), Match(start=4, end=7, dist=0)], + ) + + def test_missing_second_item_complex(self): self.assertListEqual( self.search('bde', 'abcdefg', 1, 1, 1, 1), [Match(start=1, end=5, dist=1), @@ -136,7 +195,6 @@ class TestGenericSearchBase(object): Match(start=3, end=5, dist=1)], ) - def test_missing_second_item_complex(self): self.assertTrue( set([ Match(start=1, end=5, dist=1), @@ -148,36 +206,6 @@ class TestGenericSearchBase(object): )) ) - def test_argument_handling(self): - # check that no exception is raised when some values are None - self.assertEqual( - self.search('a', 'b', 0, None, None, None), - [], - ) - - self.assertEqual( - self.search('a', 'b', None, 0, None, None), - [], - ) - - self.assertEqual( - self.search('a', 'b', None, None, 0, None), - [], - ) - - self.assertEqual( - self.search('a', 'b', None, None, None, 0), - [], - ) - - -class TestGenericSearchLP(TestGenericSearchBase, unittest.TestCase): - def search(self, pattern, sequence, max_subs, max_ins, max_dels, - max_l_dist=None): - return list(fnm_generic_lp(pattern, sequence, - max_subs, max_ins, max_dels, max_l_dist)) - - class TestGenericSearchNgrams(TestGenericSearchBase, unittest.TestCase): def search(self, pattern, sequence, max_subs, max_ins, max_dels, max_l_dist=None): @@ -185,15 +213,13 @@ class TestGenericSearchNgrams(TestGenericSearchBase, unittest.TestCase): max_subs, max_ins, max_dels, max_l_dist) def test_missing_second_item_complex(self): - pass - - @unittest.skip("Ngrams search doesn't return overlapping matches") - def test_double_first_item(self): - return super(TestGenericSearchNgrams, self).test_double_first_item() - - @unittest.skip("Ngrams search doesn't return overlapping matches") - def test_missing_second_item(self): - return super(TestGenericSearchNgrams, self).test_double_first_item() + self.assertTrue( + set(self.search('bde', 'abcdefg', 1, 1, 1, 1)).issubset([ + Match(start=1, end=5, dist=1), + Match(start=2, end=5, dist=1), + Match(start=3, end=5, dist=1), + ]) + ) class TestHasNearMatchGenericNgramsAsSubstitutionsOnly( diff --git a/tests/test_generic_search_cython.py b/tests/test_generic_search_cython.py index f2f3ee5..62ae5e5 100644 --- a/tests/test_generic_search_cython.py +++ b/tests/test_generic_search_cython.py @@ -5,11 +5,12 @@ from tests.test_substitutions_only import TestSubstitionsOnlyBase try: from fuzzysearch._generic_search import \ - c_find_near_matches_generic_linear_programming as c_fnm_generic_lp + c_find_near_matches_generic_linear_programming as c_fnm_generic_lp, \ + c_find_near_matches_generic_ngrams as c_fnm_generic_ngrams except ImportError: pass else: - class TestGenericSearchAsLevenshtein(TestFindNearMatchesLevenshteinBase, + class TestGenericSearchLpAsLevenshtein(TestFindNearMatchesLevenshteinBase, unittest.TestCase): def search(self, subsequence, sequence, max_l_dist): return [ @@ -17,13 +18,27 @@ else: for group in group_matches( c_fnm_generic_lp(subsequence.encode('ascii'), sequence.encode('ascii'), - max_l_dist, max_l_dist, max_l_dist, max_l_dist) + max_l_dist, max_l_dist, + max_l_dist, max_l_dist) + ) + ] + + class TestGenericSearchNgramsAsLevenshtein( + TestFindNearMatchesLevenshteinBase, unittest.TestCase): + def search(self, subsequence, sequence, max_l_dist): + return [ + get_best_match_in_group(group) + for group in group_matches( + c_fnm_generic_ngrams(subsequence.encode('ascii'), + sequence.encode('ascii'), + max_l_dist, max_l_dist, + max_l_dist, max_l_dist) ) ] - class TestGenericSearchAsSubstitutionsOnly(TestSubstitionsOnlyBase, - unittest.TestCase): + class TestGenericSearchLpAsSubstitutionsOnly(TestSubstitionsOnlyBase, + unittest.TestCase): def search(self, subsequence, sequence, max_subs): return list( c_fnm_generic_lp(subsequence.encode('ascii'), @@ -32,15 +47,25 @@ else: ) - class TestGenericSearch(unittest.TestCase): - def search(self, pattern, sequence, max_subs, max_ins, max_dels, - max_l_dist=None): - return list( - c_fnm_generic_lp(pattern.encode('ascii'), - sequence.encode('ascii'), - max_subs, max_ins, max_dels, max_l_dist) - ) + class TestGenericSearchNgramsAsSubstitutionsOnly(TestSubstitionsOnlyBase, + unittest.TestCase): + def search(self, subsequence, sequence, max_subs): + return [ + get_best_match_in_group(group) + for group in group_matches( + c_fnm_generic_ngrams(subsequence.encode('ascii'), + sequence.encode('ascii'), + max_subs, 0, 0, max_subs) + ) + ] + @unittest.skip("Ngrams search doesn't return overlapping matches") + def test_double_first_item(self): + return super(TestGenericSearchNgramsAsSubstitutionsOnly, + self).test_double_first_item() + + + class TestGenericSearchBase(object): def test_empty_sequence(self): self.assertEqual([], self.search('PATTERN', '', 0, 0, 0)) @@ -78,11 +103,6 @@ else: self.search('def', 'abcddefg', 1, 0, 0), ) - self.assertListEqual( - [Match(start=3, end=7, dist=1), Match(start=4, end=7, dist=0)], - self.search('def', 'abcddefg', 0, 1, 0), - ) - self.assertIn( Match(start=4, end=7, dist=0), self.search('def', 'abcddefg', 0, 0, 1), @@ -117,6 +137,65 @@ else: [Match(start=3, end=5, dist=1)], ) + def test_valid_none_arguments(self): + # check that no exception is raised when some values are None + self.assertEqual( + self.search('a', 'b', 0, None, None, 0), + [], + ) + + self.assertEqual( + self.search('a', 'b', None, 0, None, 0), + [], + ) + + self.assertEqual( + self.search('a', 'b', None, None, 0, 0), + [], + ) + + self.assertEqual( + self.search('a', 'b', 0, 0, None, 0), + [], + ) + + self.assertEqual( + self.search('a', 'b', 0, None, 0, 0), + [], + ) + + self.assertEqual( + self.search('a', 'b', None, 0, 0, 0), + [], + ) + + self.assertEqual( + self.search('a', 'b', None, None, None, 0), + [], + ) + + self.assertEqual( + self.search('a', 'b', 0, 0, 0, None), + [], + ) + + class TestGenericSearchLp(TestGenericSearchBase, unittest.TestCase): + def search(self, pattern, sequence, max_subs, max_ins, max_dels, + max_l_dist=None): + return list(c_fnm_generic_lp(pattern.encode('ascii'), + sequence.encode('ascii'), + max_subs, max_ins, + max_dels, max_l_dist)) + + def test_double_first_item_two_results(self): + # sequence = 'abcdefg' + # pattern = 'bde' + self.assertListEqual( + self.search('def', 'abcddefg', 0, 1, 0), + [Match(start=3, end=7, dist=1), Match(start=4, end=7, dist=0)], + ) + + def test_missing_second_item_complex(self): self.assertListEqual( self.search('bde', 'abcdefg', 1, 1, 1, 1), [Match(start=1, end=5, dist=1), @@ -135,24 +214,24 @@ else: )) ) - def test_argument_handling(self): - # check that no exception is raised when some values are None - self.assertEqual( - self.search('a', 'b', 0, None, None, None), - [], - ) + class TestGenericSearchNgrams(TestGenericSearchBase, unittest.TestCase): + def search(self, pattern, sequence, max_subs, max_ins, max_dels, + max_l_dist=None): + return [ + get_best_match_in_group(group) + for group in group_matches( + c_fnm_generic_ngrams(pattern.encode('ascii'), + sequence.encode('ascii'), + max_subs, max_ins, + max_dels, max_l_dist) + ) + ] - self.assertEqual( - self.search('a', 'b', None, 0, None, None), - [], - ) - - self.assertEqual( - self.search('a', 'b', None, None, 0, None), - [], - ) - - self.assertEqual( - self.search('a', 'b', None, None, None, 0), - [], + def test_missing_second_item_complex(self): + self.assertTrue( + set(self.search('bde', 'abcdefg', 1, 1, 1, 1)).issubset([ + Match(start=1, end=5, dist=1), + Match(start=2, end=5, dist=1), + Match(start=3, end=5, dist=1), + ]) )