11// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
22// SPDX-License-Identifier: MIT
33// RapidFuzz v1.0.2
4- // Generated: 2022-11-02 21:25:29.646502
4+ // Generated: 2022-11-04 11:50:47.498267
55// ----------------------------------------------------------
66// This file is an amalgamation of multiple different files.
77// You probably shouldn't edit it directly.
@@ -9014,14 +9014,13 @@ namespace fuzz_detail {
90149014
90159015template <typename InputIt1, typename InputIt2, typename CachedCharT1>
90169016ScoreAlignment<double >
9017- partial_ratio_short_needle (rapidfuzz::detail::Range<InputIt1> s1, rapidfuzz::detail::Range<InputIt2> s2,
9018- const CachedRatio<CachedCharT1>& cached_ratio,
9019- const detail::CharSet<iter_value_t <InputIt1>>& s1_char_set, double score_cutoff)
9017+ partial_ratio_impl (rapidfuzz::detail::Range<InputIt1> s1, rapidfuzz::detail::Range<InputIt2> s2,
9018+ const CachedRatio<CachedCharT1>& cached_ratio,
9019+ const detail::CharSet<iter_value_t <InputIt1>>& s1_char_set, double score_cutoff)
90209020{
90219021 ScoreAlignment<double > res;
90229022 auto len1 = static_cast <size_t >(s1.size ());
90239023 auto len2 = static_cast <size_t >(s2.size ());
9024- assert (len2 >= len1);
90259024 res.src_start = 0 ;
90269025 res.src_end = len1;
90279026 res.dest_start = 0 ;
@@ -9119,16 +9118,16 @@ partial_ratio_short_needle(rapidfuzz::detail::Range<InputIt1> s1, rapidfuzz::det
91199118}
91209119
91219120template <typename InputIt1, typename InputIt2, typename CharT1 = iter_value_t <InputIt1>>
9122- ScoreAlignment<double > partial_ratio_short_needle (rapidfuzz::detail::Range<InputIt1> s1,
9123- rapidfuzz::detail::Range<InputIt2> s2, double score_cutoff)
9121+ ScoreAlignment<double > partial_ratio_impl (rapidfuzz::detail::Range<InputIt1> s1,
9122+ rapidfuzz::detail::Range<InputIt2> s2, double score_cutoff)
91249123{
91259124 CachedRatio<CharT1> cached_ratio (s1);
91269125
91279126 detail::CharSet<CharT1> s1_char_set;
91289127 for (auto ch : s1)
91299128 s1_char_set.insert (ch);
91309129
9131- return partial_ratio_short_needle (s1, s2, cached_ratio, s1_char_set, score_cutoff);
9130+ return partial_ratio_impl (s1, s2, cached_ratio, s1_char_set, score_cutoff);
91329131}
91339132
91349133} // namespace fuzz_detail
@@ -9152,8 +9151,21 @@ ScoreAlignment<double> partial_ratio_alignment(InputIt1 first1, InputIt1 last1,
91529151 if (!len1 || !len2)
91539152 return ScoreAlignment<double >(static_cast <double >(len1 == len2) * 100.0 , 0 , len1, 0 , len1);
91549153
9155- return fuzz_detail::partial_ratio_short_needle (detail::Range (first1, last1), detail::Range (first2, last2),
9156- score_cutoff);
9154+ auto s1 = detail::Range (first1, last1);
9155+ auto s2 = detail::Range (first2, last2);
9156+
9157+ auto alignment = fuzz_detail::partial_ratio_impl (s1, s2, score_cutoff);
9158+ if (alignment.score != 100 && s1.size () == s2.size ()) {
9159+ score_cutoff = std::max (score_cutoff, alignment.score );
9160+ auto alignment2 = fuzz_detail::partial_ratio_impl (s2, s1, score_cutoff);
9161+ if (alignment2.score > alignment.score ) {
9162+ std::swap (alignment2.src_start , alignment2.dest_start );
9163+ std::swap (alignment2.src_end , alignment2.dest_end );
9164+ return alignment2;
9165+ }
9166+ }
9167+
9168+ return alignment;
91579169}
91589170
91599171template <typename Sentence1, typename Sentence2>
@@ -9199,9 +9211,17 @@ double CachedPartialRatio<CharT1>::similarity(InputIt2 first2, InputIt2 last2, d
91999211
92009212 if (!len1 || !len2) return static_cast <double >(len1 == len2) * 100.0 ;
92019213
9202- return fuzz_detail::partial_ratio_short_needle (detail::Range (s1), detail::Range (first2, last2),
9203- cached_ratio, s1_char_set, score_cutoff)
9204- .score ;
9214+ auto s1_ = detail::Range (s1);
9215+ auto s2 = detail::Range (first2, last2);
9216+
9217+ double score = fuzz_detail::partial_ratio_impl (s1_, s2, cached_ratio, s1_char_set, score_cutoff).score ;
9218+ if (score != 100 && s1_.size () == s2.size ()) {
9219+ score_cutoff = std::max (score_cutoff, score);
9220+ double score2 = fuzz_detail::partial_ratio_impl (s2, s1_, score_cutoff).score ;
9221+ if (score2 > score) return score2;
9222+ }
9223+
9224+ return score;
92059225}
92069226
92079227template <typename CharT1>
0 commit comments