Skip to content

Commit 575c1fa

Browse files
committed
fix compilation warnings on 32bit systems
1 parent 179c89f commit 575c1fa

File tree

6 files changed

+53
-47
lines changed

6 files changed

+53
-47
lines changed

extras/rapidfuzz_amalgamated.hpp

Lines changed: 31 additions & 25 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-10-24 14:07:33.184436
4+
// Generated: 2024-10-24 14:15:39.050296
55
// ----------------------------------------------------------
66
// This file is an amalgamation of multiple different files.
77
// You probably shouldn't edit it directly.
@@ -3572,7 +3572,7 @@ struct MultiSimilarityBase : public MultiNormalizedMetricBase<T, ResType> {
35723572

35733573
template <typename Sentence2>
35743574
void distance(ResType* scores, size_t score_count, const Sentence2& s2,
3575-
ResType score_cutoff = WorstDistance) const
3575+
ResType score_cutoff = static_cast<ResType>(WorstDistance)) const
35763576
{
35773577
_distance(scores, score_count, Range(s2), score_cutoff);
35783578
}
@@ -3671,26 +3671,26 @@ size_t damerau_levenshtein_distance_zhao(const Range<InputIt1>& s1, const Range<
36713671

36723672
auto iter_s2 = s2.begin();
36733673
for (IntType j = 1; j <= len2; j++) {
3674-
ptrdiff_t diag = R1[j - 1] + static_cast<IntType>(*iter_s1 != *iter_s2);
3675-
ptrdiff_t left = R[j - 1] + 1;
3676-
ptrdiff_t up = R1[j] + 1;
3677-
ptrdiff_t temp = std::min({diag, left, up});
3674+
int64_t diag = R1[j - 1] + static_cast<IntType>(*iter_s1 != *iter_s2);
3675+
int64_t left = R[j - 1] + 1;
3676+
int64_t up = R1[j] + 1;
3677+
int64_t temp = std::min({diag, left, up});
36783678

36793679
if (*iter_s1 == *iter_s2) {
36803680
last_col_id = j; // last occurence of s1_i
36813681
FR[j] = R1[j - 2]; // save H_k-1,j-2
36823682
T = last_i2l1; // save H_i-2,l-1
36833683
}
36843684
else {
3685-
ptrdiff_t k = last_row_id.get(static_cast<uint64_t>(*iter_s2)).val;
3686-
ptrdiff_t l = last_col_id;
3685+
int64_t k = last_row_id.get(static_cast<uint64_t>(*iter_s2)).val;
3686+
int64_t l = last_col_id;
36873687

36883688
if ((j - l) == 1) {
3689-
ptrdiff_t transpose = FR[j] + (i - k);
3689+
int64_t transpose = FR[j] + (i - k);
36903690
temp = std::min(temp, transpose);
36913691
}
36923692
else if ((i - k) == 1) {
3693-
ptrdiff_t transpose = T + (j - l);
3693+
int64_t transpose = T + (j - l);
36943694
temp = std::min(temp, transpose);
36953695
}
36963696
}
@@ -4482,7 +4482,7 @@ void lcs_simd(Range<size_t*> scores, const BlockPatternMatchVector& block, const
44824482
unroll<int, interleaveCount>([&](auto j) {
44834483
auto counts = popcount(~S[j]);
44844484
unroll<int, counts.size()>([&](auto i) {
4485-
*score_iter = (counts[i] >= score_cutoff) ? counts[i] : 0;
4485+
*score_iter = (counts[i] >= score_cutoff) ? static_cast<size_t>(counts[i]) : 0;
44864486
score_iter++;
44874487
});
44884488
});
@@ -4502,7 +4502,7 @@ void lcs_simd(Range<size_t*> scores, const BlockPatternMatchVector& block, const
45024502

45034503
auto counts = popcount(~S);
45044504
unroll<int, counts.size()>([&](auto i) {
4505-
*score_iter = (counts[i] >= score_cutoff) ? counts[i] : 0;
4505+
*score_iter = (counts[i] >= score_cutoff) ? static_cast<size_t>(counts[i]) : 0;
45064506
score_iter++;
45074507
});
45084508
}
@@ -5614,7 +5614,8 @@ static inline size_t count_transpositions_block(const BlockPatternMatchVector& P
56145614

56155615
uint64_t PatternFlagMask = blsi(P_flag);
56165616

5617-
Transpositions += !(PM.get(PatternWord, T_first[countr_zero(T_flag)]) & PatternFlagMask);
5617+
Transpositions += !(PM.get(PatternWord, T_first[static_cast<ptrdiff_t>(countr_zero(T_flag))]) &
5618+
PatternFlagMask);
56185619

56195620
T_flag = blsr(T_flag);
56205621
P_flag ^= PatternFlagMask;
@@ -5823,7 +5824,7 @@ static inline auto jaro_similarity_prepare_bound_short_s2(const VecType* s1_leng
58235824

58245825
// todo try to find a simd implementation for sse2
58255826
for (size_t i = 0; i < vec_width; ++i) {
5826-
size_t Bound = jaro_bounds(s1_lengths[i], s2.size());
5827+
size_t Bound = jaro_bounds(static_cast<size_t>(s1_lengths[i]), s2.size());
58275828

58285829
if (Bound > bounds.maxBound) bounds.maxBound = Bound;
58295830

@@ -5835,7 +5836,7 @@ static inline auto jaro_similarity_prepare_bound_short_s2(const VecType* s1_leng
58355836
bounds.boundMask = native_simd<VecType>(reinterpret_cast<uint64_t*>(boundMask_.data()));
58365837
# endif
58375838

5838-
size_t lastRelevantChar = maxLen + bounds.maxBound;
5839+
size_t lastRelevantChar = static_cast<size_t>(maxLen) + bounds.maxBound;
58395840
if (s2.size() > lastRelevantChar) s2.remove_suffix(s2.size() - lastRelevantChar);
58405841

58415842
return bounds;
@@ -5865,7 +5866,7 @@ static inline auto jaro_similarity_prepare_bound_long_s2(const VecType* s1_lengt
58655866
bounds.boundMaskSize = native_simd<VecType>(bit_mask_lsb<VecType>(2 * bounds.maxBound));
58665867
bounds.boundMask = native_simd<VecType>(bit_mask_lsb<VecType>(bounds.maxBound + 1));
58675868

5868-
size_t lastRelevantChar = maxLen + bounds.maxBound;
5869+
size_t lastRelevantChar = static_cast<size_t>(maxLen) + bounds.maxBound;
58695870
if (s2.size() > lastRelevantChar) s2.remove_suffix(s2.size() - lastRelevantChar);
58705871

58715872
return bounds;
@@ -5966,8 +5967,10 @@ jaro_similarity_simd_long_s2(Range<double*> scores, const detail::BlockPatternMa
59665967
T_flag[i].store(T_flags + i * vec_width);
59675968

59685969
for (size_t i = 0; i < vec_width; ++i) {
5969-
VecType CommonChars = counts[i];
5970-
if (!jaro_common_char_filter(s1_lengths[result_index], s2.size(), CommonChars, score_cutoff)) {
5970+
size_t CommonChars = static_cast<size_t>(counts[i]);
5971+
if (!jaro_common_char_filter(static_cast<size_t>(s1_lengths[result_index]), s2.size(),
5972+
CommonChars, score_cutoff))
5973+
{
59715974
scores[result_index] = 0.0;
59725975
result_index++;
59735976
continue;
@@ -6001,8 +6004,8 @@ jaro_similarity_simd_long_s2(Range<double*> scores, const detail::BlockPatternMa
60016004
}
60026005
}
60036006

6004-
double Sim =
6005-
jaro_calculate_similarity(s1_lengths[result_index], s2.size(), CommonChars, Transpositions);
6007+
double Sim = jaro_calculate_similarity(static_cast<size_t>(s1_lengths[result_index]), s2.size(),
6008+
CommonChars, Transpositions);
60066009

60076010
scores[result_index] = (Sim >= score_cutoff) ? Sim : 0;
60086011
result_index++;
@@ -6077,8 +6080,10 @@ jaro_similarity_simd_short_s2(Range<double*> scores, const detail::BlockPatternM
60776080
alignas(alignment) std::array<VecType, vec_width> T_flags;
60786081
T_flag.store(T_flags.data());
60796082
for (size_t i = 0; i < vec_width; ++i) {
6080-
VecType CommonChars = counts[i];
6081-
if (!jaro_common_char_filter(s1_lengths[result_index], s2.size(), CommonChars, score_cutoff)) {
6083+
size_t CommonChars = static_cast<size_t>(counts[i]);
6084+
if (!jaro_common_char_filter(static_cast<size_t>(s1_lengths[result_index]), s2.size(),
6085+
CommonChars, score_cutoff))
6086+
{
60826087
scores[result_index] = 0.0;
60836088
result_index++;
60846089
continue;
@@ -6101,8 +6106,8 @@ jaro_similarity_simd_short_s2(Range<double*> scores, const detail::BlockPatternM
61016106
P_flag_cur ^= PatternFlagMask;
61026107
}
61036108

6104-
double Sim =
6105-
jaro_calculate_similarity(s1_lengths[result_index], s2.size(), CommonChars, Transpositions);
6109+
double Sim = jaro_calculate_similarity(static_cast<size_t>(s1_lengths[result_index]), s2.size(),
6110+
CommonChars, Transpositions);
61066111

61076112
scores[result_index] = (Sim >= score_cutoff) ? Sim : 0;
61086113
result_index++;
@@ -7391,7 +7396,8 @@ auto levenshtein_hyrroe2003_block(const BlockPatternMatchVector& PM, const Range
73917396
vecs[last_block].VN = 0;
73927397

73937398
size_t chars_in_block = (last_block + 1 == words) ? ((s1.size() - 1) % word_size + 1) : 64;
7394-
scores[last_block] = scores[last_block - 1] + chars_in_block - HP_carry + HN_carry;
7399+
scores[last_block] = scores[last_block - 1] + chars_in_block - static_cast<size_t>(HP_carry) +
7400+
static_cast<size_t>(HN_carry);
73957401
// todo probably wrong types
73967402
scores[last_block] = static_cast<size_t>(static_cast<ptrdiff_t>(scores[last_block]) +
73977403
advance_block(last_block));

rapidfuzz/details/distance.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ struct MultiSimilarityBase : public MultiNormalizedMetricBase<T, ResType> {
501501

502502
template <typename Sentence2>
503503
void distance(ResType* scores, size_t score_count, const Sentence2& s2,
504-
ResType score_cutoff = WorstDistance) const
504+
ResType score_cutoff = static_cast<ResType>(WorstDistance)) const
505505
{
506506
_distance(scores, score_count, Range(s2), score_cutoff);
507507
}

rapidfuzz/distance/DamerauLevenshtein_impl.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,26 @@ size_t damerau_levenshtein_distance_zhao(const Range<InputIt1>& s1, const Range<
6464

6565
auto iter_s2 = s2.begin();
6666
for (IntType j = 1; j <= len2; j++) {
67-
ptrdiff_t diag = R1[j - 1] + static_cast<IntType>(*iter_s1 != *iter_s2);
68-
ptrdiff_t left = R[j - 1] + 1;
69-
ptrdiff_t up = R1[j] + 1;
70-
ptrdiff_t temp = std::min({diag, left, up});
67+
int64_t diag = R1[j - 1] + static_cast<IntType>(*iter_s1 != *iter_s2);
68+
int64_t left = R[j - 1] + 1;
69+
int64_t up = R1[j] + 1;
70+
int64_t temp = std::min({diag, left, up});
7171

7272
if (*iter_s1 == *iter_s2) {
7373
last_col_id = j; // last occurence of s1_i
7474
FR[j] = R1[j - 2]; // save H_k-1,j-2
7575
T = last_i2l1; // save H_i-2,l-1
7676
}
7777
else {
78-
ptrdiff_t k = last_row_id.get(static_cast<uint64_t>(*iter_s2)).val;
79-
ptrdiff_t l = last_col_id;
78+
int64_t k = last_row_id.get(static_cast<uint64_t>(*iter_s2)).val;
79+
int64_t l = last_col_id;
8080

8181
if ((j - l) == 1) {
82-
ptrdiff_t transpose = FR[j] + (i - k);
82+
int64_t transpose = FR[j] + (i - k);
8383
temp = std::min(temp, transpose);
8484
}
8585
else if ((i - k) == 1) {
86-
ptrdiff_t transpose = T + (j - l);
86+
int64_t transpose = T + (j - l);
8787
temp = std::min(temp, transpose);
8888
}
8989
}

rapidfuzz/distance/Jaro_impl.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ static inline size_t count_transpositions_block(const BlockPatternMatchVector& P
296296

297297
uint64_t PatternFlagMask = blsi(P_flag);
298298

299-
Transpositions += !(PM.get(PatternWord, T_first[countr_zero(T_flag)]) & PatternFlagMask);
299+
Transpositions += !(PM.get(PatternWord, T_first[static_cast<ptrdiff_t>(countr_zero(T_flag))]) & PatternFlagMask);
300300

301301
T_flag = blsr(T_flag);
302302
P_flag ^= PatternFlagMask;
@@ -505,7 +505,7 @@ static inline auto jaro_similarity_prepare_bound_short_s2(const VecType* s1_leng
505505

506506
// todo try to find a simd implementation for sse2
507507
for (size_t i = 0; i < vec_width; ++i) {
508-
size_t Bound = jaro_bounds(s1_lengths[i], s2.size());
508+
size_t Bound = jaro_bounds(static_cast<size_t>(s1_lengths[i]), s2.size());
509509

510510
if (Bound > bounds.maxBound) bounds.maxBound = Bound;
511511

@@ -517,7 +517,7 @@ static inline auto jaro_similarity_prepare_bound_short_s2(const VecType* s1_leng
517517
bounds.boundMask = native_simd<VecType>(reinterpret_cast<uint64_t*>(boundMask_.data()));
518518
# endif
519519

520-
size_t lastRelevantChar = maxLen + bounds.maxBound;
520+
size_t lastRelevantChar = static_cast<size_t>(maxLen) + bounds.maxBound;
521521
if (s2.size() > lastRelevantChar) s2.remove_suffix(s2.size() - lastRelevantChar);
522522

523523
return bounds;
@@ -547,7 +547,7 @@ static inline auto jaro_similarity_prepare_bound_long_s2(const VecType* s1_lengt
547547
bounds.boundMaskSize = native_simd<VecType>(bit_mask_lsb<VecType>(2 * bounds.maxBound));
548548
bounds.boundMask = native_simd<VecType>(bit_mask_lsb<VecType>(bounds.maxBound + 1));
549549

550-
size_t lastRelevantChar = maxLen + bounds.maxBound;
550+
size_t lastRelevantChar = static_cast<size_t>(maxLen) + bounds.maxBound;
551551
if (s2.size() > lastRelevantChar) s2.remove_suffix(s2.size() - lastRelevantChar);
552552

553553
return bounds;
@@ -648,8 +648,8 @@ jaro_similarity_simd_long_s2(Range<double*> scores, const detail::BlockPatternMa
648648
T_flag[i].store(T_flags + i * vec_width);
649649

650650
for (size_t i = 0; i < vec_width; ++i) {
651-
VecType CommonChars = counts[i];
652-
if (!jaro_common_char_filter(s1_lengths[result_index], s2.size(), CommonChars, score_cutoff)) {
651+
size_t CommonChars = static_cast<size_t>(counts[i]);
652+
if (!jaro_common_char_filter(static_cast<size_t>(s1_lengths[result_index]), s2.size(), CommonChars, score_cutoff)) {
653653
scores[result_index] = 0.0;
654654
result_index++;
655655
continue;
@@ -684,7 +684,7 @@ jaro_similarity_simd_long_s2(Range<double*> scores, const detail::BlockPatternMa
684684
}
685685

686686
double Sim =
687-
jaro_calculate_similarity(s1_lengths[result_index], s2.size(), CommonChars, Transpositions);
687+
jaro_calculate_similarity(static_cast<size_t>(s1_lengths[result_index]), s2.size(), CommonChars, Transpositions);
688688

689689
scores[result_index] = (Sim >= score_cutoff) ? Sim : 0;
690690
result_index++;
@@ -759,8 +759,8 @@ jaro_similarity_simd_short_s2(Range<double*> scores, const detail::BlockPatternM
759759
alignas(alignment) std::array<VecType, vec_width> T_flags;
760760
T_flag.store(T_flags.data());
761761
for (size_t i = 0; i < vec_width; ++i) {
762-
VecType CommonChars = counts[i];
763-
if (!jaro_common_char_filter(s1_lengths[result_index], s2.size(), CommonChars, score_cutoff)) {
762+
size_t CommonChars = static_cast<size_t>(counts[i]);
763+
if (!jaro_common_char_filter(static_cast<size_t>(s1_lengths[result_index]), s2.size(), CommonChars, score_cutoff)) {
764764
scores[result_index] = 0.0;
765765
result_index++;
766766
continue;
@@ -784,7 +784,7 @@ jaro_similarity_simd_short_s2(Range<double*> scores, const detail::BlockPatternM
784784
}
785785

786786
double Sim =
787-
jaro_calculate_similarity(s1_lengths[result_index], s2.size(), CommonChars, Transpositions);
787+
jaro_calculate_similarity(static_cast<size_t>(s1_lengths[result_index]), s2.size(), CommonChars, Transpositions);
788788

789789
scores[result_index] = (Sim >= score_cutoff) ? Sim : 0;
790790
result_index++;

rapidfuzz/distance/LCSseq_impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void lcs_simd(Range<size_t*> scores, const BlockPatternMatchVector& block, const
159159
unroll<int, interleaveCount>([&](auto j) {
160160
auto counts = popcount(~S[j]);
161161
unroll<int, counts.size()>([&](auto i) {
162-
*score_iter = (counts[i] >= score_cutoff) ? counts[i] : 0;
162+
*score_iter = (counts[i] >= score_cutoff) ? static_cast<size_t>(counts[i]) : 0;
163163
score_iter++;
164164
});
165165
});
@@ -179,7 +179,7 @@ void lcs_simd(Range<size_t*> scores, const BlockPatternMatchVector& block, const
179179

180180
auto counts = popcount(~S);
181181
unroll<int, counts.size()>([&](auto i) {
182-
*score_iter = (counts[i] >= score_cutoff) ? counts[i] : 0;
182+
*score_iter = (counts[i] >= score_cutoff) ? static_cast<size_t>(counts[i]) : 0;
183183
score_iter++;
184184
});
185185
}

rapidfuzz/distance/Levenshtein_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ auto levenshtein_hyrroe2003_block(const BlockPatternMatchVector& PM, const Range
727727
vecs[last_block].VN = 0;
728728

729729
size_t chars_in_block = (last_block + 1 == words) ? ((s1.size() - 1) % word_size + 1) : 64;
730-
scores[last_block] = scores[last_block - 1] + chars_in_block - HP_carry + HN_carry;
730+
scores[last_block] = scores[last_block - 1] + chars_in_block - static_cast<size_t>(HP_carry) + static_cast<size_t>(HN_carry);
731731
// todo probably wrong types
732732
scores[last_block] = static_cast<size_t>(static_cast<ptrdiff_t>(scores[last_block]) +
733733
advance_block(last_block));

0 commit comments

Comments
 (0)