Skip to content

Commit a673a94

Browse files
committed
fix types
1 parent 6dc8807 commit a673a94

File tree

6 files changed

+53
-56
lines changed

6 files changed

+53
-56
lines changed

extras/rapidfuzz_amalgamated.hpp

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
22
// SPDX-License-Identifier: MIT
33
// RapidFuzz v1.0.2
4-
// Generated: 2024-12-25 01:42:39.581315
4+
// Generated: 2024-12-25 02:01:10.995282
55
// ----------------------------------------------------------
66
// This file is an amalgamation of multiple different files.
77
// You probably shouldn't edit it directly.
@@ -592,7 +592,9 @@ Range(T& x) -> Range<decltype(to_begin(x))>;
592592
template <typename InputIt1, typename InputIt2>
593593
inline bool operator==(const Range<InputIt1>& a, const Range<InputIt2>& b)
594594
{
595-
return std::equal(a.begin(), a.end(), b.begin(), b.end());
595+
if (a.size() != b.size()) return false;
596+
597+
return std::equal(a.begin(), a.end(), b.begin());
596598
}
597599

598600
template <typename InputIt1, typename InputIt2>
@@ -978,13 +980,10 @@ class Editops : private std::vector<EditOp> {
978980

979981
inline bool operator==(const Editops& lhs, const Editops& rhs)
980982
{
981-
if (lhs.get_src_len() != rhs.get_src_len() || lhs.get_dest_len() != rhs.get_dest_len()) {
982-
return false;
983-
}
983+
if (lhs.get_src_len() != rhs.get_src_len() || lhs.get_dest_len() != rhs.get_dest_len()) return false;
984+
985+
if (lhs.size() != rhs.size()) return false;
984986

985-
if (lhs.size() != rhs.size()) {
986-
return false;
987-
}
988987
return std::equal(lhs.begin(), lhs.end(), rhs.begin());
989988
}
990989

@@ -1583,7 +1582,7 @@ struct UnrollImpl<T, N, Pos, true> {
15831582
{}
15841583
};
15851584

1586-
template <typename T, int N, class F>
1585+
template <typename T, T N, class F>
15871586
constexpr void unroll(F&& f)
15881587
{
15891588
UnrollImpl<T, N>::call(f);
@@ -4557,22 +4556,22 @@ void lcs_simd(Range<size_t*> scores, const BlockPatternMatchVector& block, const
45574556
size_t cur_vec = 0;
45584557
for (; cur_vec + interleaveCount * vecs <= block.size(); cur_vec += interleaveCount * vecs) {
45594558
std::array<native_simd<VecType>, interleaveCount> S;
4560-
unroll<int, interleaveCount>([&](auto j) { S[j] = static_cast<VecType>(-1); });
4559+
unroll<size_t, interleaveCount>([&](auto j) { S[j] = static_cast<VecType>(-1); });
45614560

45624561
for (const auto& ch : s2) {
4563-
unroll<int, interleaveCount>([&](auto j) {
4562+
unroll<size_t, interleaveCount>([&](auto j) {
45644563
alignas(32) std::array<uint64_t, vecs> stored;
4565-
unroll<int, vecs>([&](auto i) { stored[i] = block.get(cur_vec + j * vecs + i, ch); });
4564+
unroll<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + j * vecs + i, ch); });
45664565

45674566
native_simd<VecType> Matches(stored.data());
45684567
native_simd<VecType> u = S[j] & Matches;
45694568
S[j] = (S[j] + u) | (S[j] - u);
45704569
});
45714570
}
45724571

4573-
unroll<int, interleaveCount>([&](auto j) {
4572+
unroll<size_t, interleaveCount>([&](auto j) {
45744573
auto counts = popcount(~S[j]);
4575-
unroll<int, counts.size()>([&](auto i) {
4574+
unroll<size_t, counts.size()>([&](auto i) {
45764575
*score_iter = (counts[i] >= score_cutoff) ? static_cast<size_t>(counts[i]) : 0;
45774576
score_iter++;
45784577
});
@@ -4584,15 +4583,15 @@ void lcs_simd(Range<size_t*> scores, const BlockPatternMatchVector& block, const
45844583

45854584
for (const auto& ch : s2) {
45864585
alignas(alignment) std::array<uint64_t, vecs> stored;
4587-
unroll<int, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, ch); });
4586+
unroll<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, ch); });
45884587

45894588
native_simd<VecType> Matches(stored.data());
45904589
native_simd<VecType> u = S & Matches;
45914590
S = (S + u) | (S - u);
45924591
}
45934592

45944593
auto counts = popcount(~S);
4595-
unroll<int, counts.size()>([&](auto i) {
4594+
unroll<size_t, counts.size()>([&](auto i) {
45964595
*score_iter = (counts[i] >= score_cutoff) ? static_cast<size_t>(counts[i]) : 0;
45974596
score_iter++;
45984597
});
@@ -4783,8 +4782,7 @@ size_t lcs_seq_similarity(const BlockPatternMatchVector& block, Range<InputIt1>
47834782
size_t max_misses = len1 + len2 - 2 * score_cutoff;
47844783

47854784
/* no edits are allowed */
4786-
if (max_misses == 0 || (max_misses == 1 && len1 == len2))
4787-
return std::equal(s1.begin(), s1.end(), s2.begin(), s2.end()) ? len1 : 0;
4785+
if (max_misses == 0 || (max_misses == 1 && len1 == len2)) return s1 == s2 ? len1 : 0;
47884786

47894787
if (max_misses < abs_diff(len1, len2)) return 0;
47904788

@@ -4816,8 +4814,7 @@ size_t lcs_seq_similarity(Range<InputIt1> s1, Range<InputIt2> s2, size_t score_c
48164814
size_t max_misses = len1 + len2 - 2 * score_cutoff;
48174815

48184816
/* no edits are allowed */
4819-
if (max_misses == 0 || (max_misses == 1 && len1 == len2))
4820-
return std::equal(s1.begin(), s1.end(), s2.begin(), s2.end()) ? len1 : 0;
4817+
if (max_misses == 0 || (max_misses == 1 && len1 == len2)) return s1 == s2 ? len1 : 0;
48214818

48224819
if (max_misses < abs_diff(len1, len2)) return 0;
48234820

@@ -5593,7 +5590,7 @@ static inline void flag_similar_characters_step(const BlockPatternMatchVector& P
55935590
if (T_j >= 0 && T_j < 256) {
55945591
for (; word + 3 < last_word - 1; word += 4) {
55955592
uint64_t PM_j[4];
5596-
unroll<int, 4>([&](auto i) {
5593+
unroll<size_t, 4>([&](auto i) {
55975594
PM_j[i] = PM.get(word + i, static_cast<uint8_t>(T_j)) & (~flagged.P_flag[word + i]);
55985595
});
55995596

@@ -6048,7 +6045,7 @@ jaro_similarity_simd_long_s2(Range<double*> scores, const detail::BlockPatternMa
60486045
size_t j = 0;
60496046
for (; j < std::min(bounds.maxBound, s2_cur.size()); ++j) {
60506047
alignas(alignment) std::array<uint64_t, vecs> stored;
6051-
unroll<int, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, s2_cur[j]); });
6048+
unroll<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, s2_cur[j]); });
60526049
native_simd<VecType> X(stored.data());
60536050
native_simd<VecType> PM_j = andnot(X & bounds.boundMask, P_flag);
60546051

@@ -6062,7 +6059,7 @@ jaro_similarity_simd_long_s2(Range<double*> scores, const detail::BlockPatternMa
60626059

60636060
for (; j < s2_cur.size(); ++j) {
60646061
alignas(alignment) std::array<uint64_t, vecs> stored;
6065-
unroll<int, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, s2_cur[j]); });
6062+
unroll<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, s2_cur[j]); });
60666063
native_simd<VecType> X(stored.data());
60676064
native_simd<VecType> PM_j = andnot(X & bounds.boundMask, P_flag);
60686065

@@ -6165,7 +6162,7 @@ jaro_similarity_simd_short_s2(Range<double*> scores, const detail::BlockPatternM
61656162
size_t j = 0;
61666163
for (; j < std::min(bounds.maxBound, s2_cur.size()); ++j) {
61676164
alignas(alignment) std::array<uint64_t, vecs> stored;
6168-
unroll<int, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, s2_cur[j]); });
6165+
unroll<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, s2_cur[j]); });
61696166
native_simd<VecType> X(stored.data());
61706167
native_simd<VecType> PM_j = andnot(X & bounds.boundMask, P_flag);
61716168

@@ -6178,7 +6175,7 @@ jaro_similarity_simd_short_s2(Range<double*> scores, const detail::BlockPatternM
61786175

61796176
for (; j < s2_cur.size(); ++j) {
61806177
alignas(alignment) std::array<uint64_t, vecs> stored;
6181-
unroll<int, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, s2_cur[j]); });
6178+
unroll<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, s2_cur[j]); });
61826179
native_simd<VecType> X(stored.data());
61836180
native_simd<VecType> PM_j = andnot(X & bounds.boundMask, P_flag);
61846181

@@ -7138,12 +7135,12 @@ void levenshtein_hyrroe2003_simd(Range<size_t*> scores, const detail::BlockPatte
71387135
native_simd<VecType> VN(VecType(0));
71397136

71407137
alignas(alignment) std::array<VecType, vec_width> currDist_;
7141-
unroll<int, vec_width>(
7138+
unroll<size_t, vec_width>(
71427139
[&](auto i) { currDist_[i] = static_cast<VecType>(s1_lengths[result_index + i]); });
71437140
native_simd<VecType> currDist(reinterpret_cast<uint64_t*>(currDist_.data()));
71447141
/* mask used when computing D[m,j] in the paper 10^(m-1) */
71457142
alignas(alignment) std::array<VecType, vec_width> mask_;
7146-
unroll<int, vec_width>([&](auto i) {
7143+
unroll<size_t, vec_width>([&](auto i) {
71477144
if (s1_lengths[result_index + i] == 0)
71487145
mask_[i] = 0;
71497146
else
@@ -7154,7 +7151,7 @@ void levenshtein_hyrroe2003_simd(Range<size_t*> scores, const detail::BlockPatte
71547151
for (const auto& ch : s2) {
71557152
/* Step 1: Computing D0 */
71567153
alignas(alignment) std::array<uint64_t, vecs> stored;
7157-
unroll<int, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, ch); });
7154+
unroll<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, ch); });
71587155

71597156
native_simd<VecType> X(stored.data());
71607157
auto D0 = (((X & VP) + VP) ^ VP) | X | VN;
@@ -7178,7 +7175,7 @@ void levenshtein_hyrroe2003_simd(Range<size_t*> scores, const detail::BlockPatte
71787175
alignas(alignment) std::array<VecType, vec_width> distances;
71797176
currDist.store(distances.data());
71807177

7181-
unroll<int, vec_width>([&](auto i) {
7178+
unroll<size_t, vec_width>([&](auto i) {
71827179
size_t score = 0;
71837180
/* strings of length 0 are not handled correctly */
71847181
if (s1_lengths[result_index] == 0) {
@@ -7649,7 +7646,7 @@ size_t uniform_levenshtein_distance(const BlockPatternMatchVector& block, Range<
76497646
if (score_hint < 31) score_hint = 31;
76507647

76517648
// when no differences are allowed a direct comparision is sufficient
7652-
if (score_cutoff == 0) return !std::equal(s1.begin(), s1.end(), s2.begin(), s2.end());
7649+
if (score_cutoff == 0) return s1 != s2;
76537650

76547651
if (score_cutoff < abs_diff(s1.size(), s2.size())) return score_cutoff + 1;
76557652

@@ -7707,7 +7704,7 @@ size_t uniform_levenshtein_distance(Range<InputIt1> s1, Range<InputIt2> s2, size
77077704
if (score_hint < 31) score_hint = 31;
77087705

77097706
// when no differences are allowed a direct comparision is sufficient
7710-
if (score_cutoff == 0) return !std::equal(s1.begin(), s1.end(), s2.begin(), s2.end());
7707+
if (score_cutoff == 0) return s1 != s2;
77117708

77127709
// at least length difference insertions/deletions required
77137710
if (score_cutoff < (s1.size() - s2.size())) return score_cutoff + 1;
@@ -8635,12 +8632,12 @@ void osa_hyrroe2003_simd(Range<size_t*> scores, const detail::BlockPatternMatchV
86358632
native_simd<VecType> PM_j_old(VecType(0));
86368633

86378634
alignas(alignment) std::array<VecType, vec_width> currDist_;
8638-
unroll<int, vec_width>(
8635+
unroll<size_t, vec_width>(
86398636
[&](auto i) { currDist_[i] = static_cast<VecType>(s1_lengths[result_index + i]); });
86408637
native_simd<VecType> currDist(reinterpret_cast<uint64_t*>(currDist_.data()));
86418638
/* mask used when computing D[m,j] in the paper 10^(m-1) */
86428639
alignas(alignment) std::array<VecType, vec_width> mask_;
8643-
unroll<int, vec_width>([&](auto i) {
8640+
unroll<size_t, vec_width>([&](auto i) {
86448641
if (s1_lengths[result_index + i] == 0)
86458642
mask_[i] = 0;
86468643
else
@@ -8651,7 +8648,7 @@ void osa_hyrroe2003_simd(Range<size_t*> scores, const detail::BlockPatternMatchV
86518648
for (const auto& ch : s2) {
86528649
/* Step 1: Computing D0 */
86538650
alignas(alignment) std::array<uint64_t, vecs> stored;
8654-
unroll<int, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, ch); });
8651+
unroll<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, ch); });
86558652

86568653
native_simd<VecType> PM_j(stored.data());
86578654
auto TR = (andnot(PM_j, D0) << 1) & PM_j_old;
@@ -8678,7 +8675,7 @@ void osa_hyrroe2003_simd(Range<size_t*> scores, const detail::BlockPatternMatchV
86788675
alignas(alignment) std::array<VecType, vec_width> distances;
86798676
currDist.store(distances.data());
86808677

8681-
unroll<int, vec_width>([&](auto i) {
8678+
unroll<size_t, vec_width>([&](auto i) {
86828679
size_t score = 0;
86838680
/* strings of length 0 are not handled correctly */
86848681
if (s1_lengths[result_index] == 0) {

rapidfuzz/details/intrinsics.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ struct UnrollImpl<T, N, Pos, true> {
218218
{}
219219
};
220220

221-
template <typename T, int N, class F>
221+
template <typename T, T N, class F>
222222
constexpr void unroll(F&& f)
223223
{
224224
UnrollImpl<T, N>::call(f);

rapidfuzz/distance/Jaro_impl.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ static inline void flag_similar_characters_step(const BlockPatternMatchVector& P
161161
if (T_j >= 0 && T_j < 256) {
162162
for (; word + 3 < last_word - 1; word += 4) {
163163
uint64_t PM_j[4];
164-
unroll<int, 4>([&](auto i) {
164+
unroll<size_t, 4>([&](auto i) {
165165
PM_j[i] = PM.get(word + i, static_cast<uint8_t>(T_j)) & (~flagged.P_flag[word + i]);
166166
});
167167

@@ -616,7 +616,7 @@ jaro_similarity_simd_long_s2(Range<double*> scores, const detail::BlockPatternMa
616616
size_t j = 0;
617617
for (; j < std::min(bounds.maxBound, s2_cur.size()); ++j) {
618618
alignas(alignment) std::array<uint64_t, vecs> stored;
619-
unroll<int, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, s2_cur[j]); });
619+
unroll<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, s2_cur[j]); });
620620
native_simd<VecType> X(stored.data());
621621
native_simd<VecType> PM_j = andnot(X & bounds.boundMask, P_flag);
622622

@@ -630,7 +630,7 @@ jaro_similarity_simd_long_s2(Range<double*> scores, const detail::BlockPatternMa
630630

631631
for (; j < s2_cur.size(); ++j) {
632632
alignas(alignment) std::array<uint64_t, vecs> stored;
633-
unroll<int, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, s2_cur[j]); });
633+
unroll<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, s2_cur[j]); });
634634
native_simd<VecType> X(stored.data());
635635
native_simd<VecType> PM_j = andnot(X & bounds.boundMask, P_flag);
636636

@@ -733,7 +733,7 @@ jaro_similarity_simd_short_s2(Range<double*> scores, const detail::BlockPatternM
733733
size_t j = 0;
734734
for (; j < std::min(bounds.maxBound, s2_cur.size()); ++j) {
735735
alignas(alignment) std::array<uint64_t, vecs> stored;
736-
unroll<int, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, s2_cur[j]); });
736+
unroll<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, s2_cur[j]); });
737737
native_simd<VecType> X(stored.data());
738738
native_simd<VecType> PM_j = andnot(X & bounds.boundMask, P_flag);
739739

@@ -746,7 +746,7 @@ jaro_similarity_simd_short_s2(Range<double*> scores, const detail::BlockPatternM
746746

747747
for (; j < s2_cur.size(); ++j) {
748748
alignas(alignment) std::array<uint64_t, vecs> stored;
749-
unroll<int, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, s2_cur[j]); });
749+
unroll<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, s2_cur[j]); });
750750
native_simd<VecType> X(stored.data());
751751
native_simd<VecType> PM_j = andnot(X & bounds.boundMask, P_flag);
752752

rapidfuzz/distance/LCSseq_impl.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,22 @@ void lcs_simd(Range<size_t*> scores, const BlockPatternMatchVector& block, const
158158
size_t cur_vec = 0;
159159
for (; cur_vec + interleaveCount * vecs <= block.size(); cur_vec += interleaveCount * vecs) {
160160
std::array<native_simd<VecType>, interleaveCount> S;
161-
unroll<int, interleaveCount>([&](auto j) { S[j] = static_cast<VecType>(-1); });
161+
unroll<size_t, interleaveCount>([&](auto j) { S[j] = static_cast<VecType>(-1); });
162162

163163
for (const auto& ch : s2) {
164-
unroll<int, interleaveCount>([&](auto j) {
164+
unroll<size_t, interleaveCount>([&](auto j) {
165165
alignas(32) std::array<uint64_t, vecs> stored;
166-
unroll<int, vecs>([&](auto i) { stored[i] = block.get(cur_vec + j * vecs + i, ch); });
166+
unroll<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + j * vecs + i, ch); });
167167

168168
native_simd<VecType> Matches(stored.data());
169169
native_simd<VecType> u = S[j] & Matches;
170170
S[j] = (S[j] + u) | (S[j] - u);
171171
});
172172
}
173173

174-
unroll<int, interleaveCount>([&](auto j) {
174+
unroll<size_t, interleaveCount>([&](auto j) {
175175
auto counts = popcount(~S[j]);
176-
unroll<int, counts.size()>([&](auto i) {
176+
unroll<size_t, counts.size()>([&](auto i) {
177177
*score_iter = (counts[i] >= score_cutoff) ? static_cast<size_t>(counts[i]) : 0;
178178
score_iter++;
179179
});
@@ -185,15 +185,15 @@ void lcs_simd(Range<size_t*> scores, const BlockPatternMatchVector& block, const
185185

186186
for (const auto& ch : s2) {
187187
alignas(alignment) std::array<uint64_t, vecs> stored;
188-
unroll<int, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, ch); });
188+
unroll<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, ch); });
189189

190190
native_simd<VecType> Matches(stored.data());
191191
native_simd<VecType> u = S & Matches;
192192
S = (S + u) | (S - u);
193193
}
194194

195195
auto counts = popcount(~S);
196-
unroll<int, counts.size()>([&](auto i) {
196+
unroll<size_t, counts.size()>([&](auto i) {
197197
*score_iter = (counts[i] >= score_cutoff) ? static_cast<size_t>(counts[i]) : 0;
198198
score_iter++;
199199
});

rapidfuzz/distance/Levenshtein_impl.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,12 @@ void levenshtein_hyrroe2003_simd(Range<size_t*> scores, const detail::BlockPatte
347347
native_simd<VecType> VN(VecType(0));
348348

349349
alignas(alignment) std::array<VecType, vec_width> currDist_;
350-
unroll<int, vec_width>(
350+
unroll<size_t, vec_width>(
351351
[&](auto i) { currDist_[i] = static_cast<VecType>(s1_lengths[result_index + i]); });
352352
native_simd<VecType> currDist(reinterpret_cast<uint64_t*>(currDist_.data()));
353353
/* mask used when computing D[m,j] in the paper 10^(m-1) */
354354
alignas(alignment) std::array<VecType, vec_width> mask_;
355-
unroll<int, vec_width>([&](auto i) {
355+
unroll<size_t, vec_width>([&](auto i) {
356356
if (s1_lengths[result_index + i] == 0)
357357
mask_[i] = 0;
358358
else
@@ -363,7 +363,7 @@ void levenshtein_hyrroe2003_simd(Range<size_t*> scores, const detail::BlockPatte
363363
for (const auto& ch : s2) {
364364
/* Step 1: Computing D0 */
365365
alignas(alignment) std::array<uint64_t, vecs> stored;
366-
unroll<int, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, ch); });
366+
unroll<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, ch); });
367367

368368
native_simd<VecType> X(stored.data());
369369
auto D0 = (((X & VP) + VP) ^ VP) | X | VN;
@@ -387,7 +387,7 @@ void levenshtein_hyrroe2003_simd(Range<size_t*> scores, const detail::BlockPatte
387387
alignas(alignment) std::array<VecType, vec_width> distances;
388388
currDist.store(distances.data());
389389

390-
unroll<int, vec_width>([&](auto i) {
390+
unroll<size_t, vec_width>([&](auto i) {
391391
size_t score = 0;
392392
/* strings of length 0 are not handled correctly */
393393
if (s1_lengths[result_index] == 0) {

0 commit comments

Comments
 (0)