1
1
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
2
2
// SPDX-License-Identifier: MIT
3
3
// RapidFuzz v1.0.2
4
- // Generated: 2024-04-06 15:39 :26.940916
4
+ // Generated: 2024-07-02 16:47 :26.932914
5
5
// ----------------------------------------------------------
6
6
// This file is an amalgamation of multiple different files.
7
7
// You probably shouldn't edit it directly.
@@ -7719,6 +7719,9 @@ template <typename InputIt1, typename InputIt2>
7719
7719
HirschbergPos find_hirschberg_pos (const Range<InputIt1>& s1, const Range<InputIt2>& s2,
7720
7720
size_t max = std::numeric_limits<size_t >::max())
7721
7721
{
7722
+ assert (s1.size () > 1 );
7723
+ assert (s2.size () > 1 );
7724
+
7722
7725
HirschbergPos hpos = {};
7723
7726
size_t left_size = s2.size () / 2 ;
7724
7727
size_t right_size = s2.size () - left_size;
@@ -7727,8 +7730,9 @@ HirschbergPos find_hirschberg_pos(const Range<InputIt1>& s1, const Range<InputIt
7727
7730
size_t best_score = std::numeric_limits<size_t >::max ();
7728
7731
size_t right_first_pos = 0 ;
7729
7732
size_t right_last_pos = 0 ;
7733
+ // todo: we could avoid this allocation by counting up the right score twice
7734
+ // not sure whats faster though
7730
7735
std::vector<size_t > right_scores;
7731
-
7732
7736
{
7733
7737
auto right_row = levenshtein_row (s1.reversed (), s2.reversed (), max, right_size - 1 );
7734
7738
if (right_row.dist > max) return find_hirschberg_pos (s1, s2, max * 2 );
@@ -7758,6 +7762,17 @@ HirschbergPos find_hirschberg_pos(const Range<InputIt1>& s1, const Range<InputIt
7758
7762
auto left_last_pos = std::min (s1_len, left_row.last_block * 64 + 64 );
7759
7763
7760
7764
size_t left_score = left_row.prev_score ;
7765
+ // take boundary into account
7766
+ if (s1_len >= left_first_pos + right_first_pos) {
7767
+ size_t right_index = s1_len - left_first_pos - right_first_pos;
7768
+ if (right_index < right_scores.size ()) {
7769
+ best_score = right_scores[right_index] + left_score;
7770
+ hpos.left_score = left_score;
7771
+ hpos.right_score = right_scores[right_index];
7772
+ hpos.s1_mid = left_first_pos;
7773
+ }
7774
+ }
7775
+
7761
7776
for (size_t i = left_first_pos; i < left_last_pos; ++i) {
7762
7777
size_t col_pos = i % 64 ;
7763
7778
size_t col_word = i / 64 ;
0 commit comments