Skip to content

Commit

Permalink
cleanup duplicated code for score_cutoff conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbachmann committed Dec 28, 2023
1 parent d276bb8 commit 5564f01
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 133 deletions.
14 changes: 4 additions & 10 deletions src/rapidfuzz/cpp_common.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from cpython.object cimport PyObject
from cpython.pycapsule cimport PyCapsule_GetPointer, PyCapsule_IsValid, PyCapsule_New
from libc.stddef cimport wchar_t
from libc.stdint cimport int64_t, uint64_t
from libc.stdint cimport int64_t, uint64_t, SIZE_MAX
from libc.stdlib cimport free, malloc
from libcpp cimport bool
from libcpp.utility cimport move, pair
Expand Down Expand Up @@ -332,9 +332,7 @@ cdef inline RF_String conv_sequence(seq) except *:
else:
return move(hash_sequence(seq))

cdef inline double get_score_cutoff_f64(score_cutoff, const RF_ScorerFlags* scorer_flags) except *:
cdef float worst_score = scorer_flags.worst_score.f64
cdef float optimal_score = scorer_flags.optimal_score.f64
cdef inline double get_score_cutoff_f64(score_cutoff, float worst_score, float optimal_score) except *:
cdef float c_score_cutoff = worst_score

if score_cutoff is not None:
Expand All @@ -350,9 +348,7 @@ cdef inline double get_score_cutoff_f64(score_cutoff, const RF_ScorerFlags* scor

return c_score_cutoff

cdef inline int64_t get_score_cutoff_i64(score_cutoff, const RF_ScorerFlags* scorer_flags) except *:
cdef int64_t worst_score = scorer_flags.worst_score.i64
cdef int64_t optimal_score = scorer_flags.optimal_score.i64
cdef inline int64_t get_score_cutoff_i64(score_cutoff, int64_t worst_score, int64_t optimal_score) except *:
cdef int64_t c_score_cutoff = worst_score

if score_cutoff is not None:
Expand All @@ -368,9 +364,7 @@ cdef inline int64_t get_score_cutoff_i64(score_cutoff, const RF_ScorerFlags* sco

return c_score_cutoff

cdef inline size_t get_score_cutoff_size_t(score_cutoff, const RF_ScorerFlags* scorer_flags) except *:
cdef size_t worst_score = scorer_flags.worst_score.sizet
cdef size_t optimal_score = scorer_flags.optimal_score.sizet
cdef inline size_t get_score_cutoff_size_t(score_cutoff, size_t worst_score, size_t optimal_score) except *:
cdef size_t c_score_cutoff = worst_score

if score_cutoff is not None:
Expand Down
Loading

0 comments on commit 5564f01

Please sign in to comment.