Skip to content

Commit 4e928a1

Browse files
committed
fix some more issues
1 parent a673a94 commit 4e928a1

File tree

14 files changed

+318
-309
lines changed

14 files changed

+318
-309
lines changed

extras/rapidfuzz_amalgamated.hpp

Lines changed: 266 additions & 262 deletions
Large diffs are not rendered by default.

rapidfuzz/details/Matrix.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ struct BitMatrixView {
1616

1717
using value_type = T;
1818
using size_type = size_t;
19-
using pointer = std::conditional_t<IsConst, const value_type*, value_type*>;
20-
using reference = std::conditional_t<IsConst, const value_type&, value_type&>;
19+
using pointer = typename std::conditional<IsConst, const value_type*, value_type*>::type;
20+
using reference = typename std::conditional<IsConst, const value_type&, value_type&>::type;
2121

2222
BitMatrixView(pointer vector, size_type cols) noexcept : m_vector(vector), m_cols(cols)
2323
{}

rapidfuzz/details/Range.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <sys/types.h>
1414
#include <vector>
1515

16+
#include <rapidfuzz/details/type_traits.hpp>
17+
1618
namespace rapidfuzz {
1719
namespace detail {
1820

@@ -119,7 +121,7 @@ class Range {
119121
}
120122

121123
template <typename... Dummy, typename IterCopy = Iter,
122-
typename = std::enable_if_t<
124+
typename = rapidfuzz::rf_enable_if_t<
123125
std::is_base_of<std::random_access_iterator_tag,
124126
typename std::iterator_traits<IterCopy>::iterator_category>::value>>
125127
constexpr decltype(auto) operator[](size_t n) const

rapidfuzz/details/common_impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ size_t remove_common_prefix(Range<InputIt1>& s1, Range<InputIt2>& s2)
5454
template <typename InputIt1, typename InputIt2>
5555
size_t remove_common_suffix(Range<InputIt1>& s1, Range<InputIt2>& s2)
5656
{
57-
auto rfirst1 = std::rbegin(s1);
57+
auto rfirst1 = s1.rbegin();
5858
size_t suffix = static_cast<size_t>(
59-
std::distance(rfirst1, std::mismatch(rfirst1, std::rend(s1), std::rbegin(s2), std::rend(s2)).first));
59+
std::distance(rfirst1, std::mismatch(rfirst1, s1.rend(), s2.rbegin(), s2.rend()).first));
6060
s1.remove_suffix(suffix);
6161
s2.remove_suffix(suffix);
6262
return suffix;

rapidfuzz/details/distance.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace detail {
1515
template <typename T, typename... Args>
1616
struct NormalizedMetricBase {
1717
template <typename InputIt1, typename InputIt2,
18-
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
18+
typename = rapidfuzz::rf_enable_if_t<!std::is_same<InputIt2, double>::value>>
1919
static double normalized_distance(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2,
2020
Args... args, double score_cutoff, double score_hint)
2121
{
@@ -32,7 +32,7 @@ struct NormalizedMetricBase {
3232
}
3333

3434
template <typename InputIt1, typename InputIt2,
35-
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
35+
typename = rapidfuzz::rf_enable_if_t<!std::is_same<InputIt2, double>::value>>
3636
static double normalized_similarity(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2,
3737
Args... args, double score_cutoff, double score_hint)
3838
{
@@ -83,7 +83,7 @@ struct NormalizedMetricBase {
8383
template <typename T, typename ResType, int64_t WorstSimilarity, int64_t WorstDistance, typename... Args>
8484
struct DistanceBase : public NormalizedMetricBase<T, Args...> {
8585
template <typename InputIt1, typename InputIt2,
86-
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
86+
typename = rapidfuzz::rf_enable_if_t<!std::is_same<InputIt2, double>::value>>
8787
static ResType distance(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Args... args,
8888
ResType score_cutoff, ResType score_hint)
8989
{
@@ -99,7 +99,7 @@ struct DistanceBase : public NormalizedMetricBase<T, Args...> {
9999
}
100100

101101
template <typename InputIt1, typename InputIt2,
102-
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
102+
typename = rapidfuzz::rf_enable_if_t<!std::is_same<InputIt2, double>::value>>
103103
static ResType similarity(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Args... args,
104104
ResType score_cutoff, ResType score_hint)
105105
{
@@ -138,7 +138,7 @@ struct DistanceBase : public NormalizedMetricBase<T, Args...> {
138138
template <typename T, typename ResType, int64_t WorstSimilarity, int64_t WorstDistance, typename... Args>
139139
struct SimilarityBase : public NormalizedMetricBase<T, Args...> {
140140
template <typename InputIt1, typename InputIt2,
141-
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
141+
typename = rapidfuzz::rf_enable_if_t<!std::is_same<InputIt2, double>::value>>
142142
static ResType distance(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Args... args,
143143
ResType score_cutoff, ResType score_hint)
144144
{
@@ -154,7 +154,7 @@ struct SimilarityBase : public NormalizedMetricBase<T, Args...> {
154154
}
155155

156156
template <typename InputIt1, typename InputIt2,
157-
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
157+
typename = rapidfuzz::rf_enable_if_t<!std::is_same<InputIt2, double>::value>>
158158
static ResType similarity(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Args... args,
159159
ResType score_cutoff, ResType score_hint)
160160
{
@@ -185,14 +185,14 @@ struct SimilarityBase : public NormalizedMetricBase<T, Args...> {
185185
}
186186

187187
template <typename U>
188-
static std::enable_if_t<std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
188+
static rapidfuzz::rf_enable_if_t<std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
189189
U score_cutoff)
190190
{
191191
return (score <= score_cutoff) ? score : 1.0;
192192
}
193193

194194
template <typename U>
195-
static std::enable_if_t<!std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
195+
static rapidfuzz::rf_enable_if_t<!std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
196196
U score_cutoff)
197197
{
198198
return (score <= score_cutoff) ? score : score_cutoff + 1;
@@ -365,14 +365,14 @@ struct CachedSimilarityBase : public CachedNormalizedMetricBase<T> {
365365
}
366366

367367
template <typename U>
368-
static std::enable_if_t<std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
368+
static rapidfuzz::rf_enable_if_t<std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
369369
U score_cutoff)
370370
{
371371
return (score <= score_cutoff) ? score : 1.0;
372372
}
373373

374374
template <typename U>
375-
static std::enable_if_t<!std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
375+
static rapidfuzz::rf_enable_if_t<!std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
376376
U score_cutoff)
377377
{
378378
return (score <= score_cutoff) ? score : score_cutoff + 1;
@@ -559,14 +559,14 @@ struct MultiSimilarityBase : public MultiNormalizedMetricBase<T, ResType> {
559559
}
560560

561561
template <typename U>
562-
static std::enable_if_t<std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
562+
static rapidfuzz::rf_enable_if_t<std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
563563
U score_cutoff)
564564
{
565565
return (score <= score_cutoff) ? score : 1.0;
566566
}
567567

568568
template <typename U>
569-
static std::enable_if_t<!std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
569+
static rapidfuzz::rf_enable_if_t<!std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
570570
U score_cutoff)
571571
{
572572
return (score <= score_cutoff) ? score : score_cutoff + 1;

rapidfuzz/details/type_traits.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,7 @@ struct is_explicitly_convertible {
4949
static bool const value = test<From, To>(0);
5050
};
5151

52+
template<bool B, class T = void>
53+
using rf_enable_if_t = typename std::enable_if<B, T>::type;
54+
5255
} // namespace rapidfuzz

rapidfuzz/distance/Jaro.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ struct MultiJaro : public detail::MultiSimilarityBase<MultiJaro<MaxLen>, double,
7272

7373
static_assert(MaxLen == 8 || MaxLen == 16 || MaxLen == 32 || MaxLen == 64);
7474

75-
using VecType = typename std::conditional_t<
75+
using VecType = typename std::conditional<
7676
MaxLen == 8, uint8_t,
77-
typename std::conditional_t<MaxLen == 16, uint16_t,
78-
typename std::conditional_t<MaxLen == 32, uint32_t, uint64_t>>>;
77+
typename std::conditional<MaxLen == 16, uint16_t,
78+
typename std::conditional<MaxLen == 32, uint32_t, uint64_t>::type>::type>::type;
7979

8080
constexpr static size_t get_vec_size()
8181
{

rapidfuzz/distance/JaroWinkler.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace rapidfuzz {
1010

1111
template <typename InputIt1, typename InputIt2,
12-
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
12+
typename = rapidfuzz::rf_enable_if_t<!std::is_same<InputIt2, double>::value>>
1313
double jaro_winkler_distance(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2,
1414
double prefix_weight = 0.1, double score_cutoff = 1.0)
1515
{
@@ -25,7 +25,7 @@ double jaro_winkler_distance(const Sentence1& s1, const Sentence2& s2, double pr
2525
}
2626

2727
template <typename InputIt1, typename InputIt2,
28-
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
28+
typename = rapidfuzz::rf_enable_if_t<!std::is_same<InputIt2, double>::value>>
2929
double jaro_winkler_similarity(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2,
3030
double prefix_weight = 0.1, double score_cutoff = 0.0)
3131
{
@@ -41,7 +41,7 @@ double jaro_winkler_similarity(const Sentence1& s1, const Sentence2& s2, double
4141
}
4242

4343
template <typename InputIt1, typename InputIt2,
44-
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
44+
typename = rapidfuzz::rf_enable_if_t<!std::is_same<InputIt2, double>::value>>
4545
double jaro_winkler_normalized_distance(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2,
4646
double prefix_weight = 0.1, double score_cutoff = 1.0)
4747
{
@@ -57,7 +57,7 @@ double jaro_winkler_normalized_distance(const Sentence1& s1, const Sentence2& s2
5757
}
5858

5959
template <typename InputIt1, typename InputIt2,
60-
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
60+
typename = rapidfuzz::rf_enable_if_t<!std::is_same<InputIt2, double>::value>>
6161
double jaro_winkler_normalized_similarity(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2,
6262
double prefix_weight = 0.1, double score_cutoff = 0.0)
6363
{

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<size_t, 4>([&](auto i) {
164+
unroll<size_t, 4>([&](size_t 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<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, s2_cur[j]); });
619+
unroll<size_t, vecs>([&](size_t 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<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, s2_cur[j]); });
633+
unroll<size_t, vecs>([&](size_t 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<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, s2_cur[j]); });
736+
unroll<size_t, vecs>([&](size_t 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<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, s2_cur[j]); });
749+
unroll<size_t, vecs>([&](size_t 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<size_t, interleaveCount>([&](auto j) { S[j] = static_cast<VecType>(-1); });
161+
unroll<size_t, interleaveCount>([&](size_t j) { S[j] = static_cast<VecType>(-1); });
162162

163163
for (const auto& ch : s2) {
164-
unroll<size_t, interleaveCount>([&](auto j) {
164+
unroll<size_t, interleaveCount>([&](size_t j) {
165165
alignas(32) std::array<uint64_t, vecs> stored;
166-
unroll<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + j * vecs + i, ch); });
166+
unroll<size_t, vecs>([&](size_t 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<size_t, interleaveCount>([&](auto j) {
174+
unroll<size_t, interleaveCount>([&](size_t j) {
175175
auto counts = popcount(~S[j]);
176-
unroll<size_t, counts.size()>([&](auto i) {
176+
unroll<size_t, counts.size()>([&](size_t 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<size_t, vecs>([&](auto i) { stored[i] = block.get(cur_vec + i, ch); });
188+
unroll<size_t, vecs>([&](size_t 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<size_t, counts.size()>([&](auto i) {
196+
unroll<size_t, counts.size()>([&](size_t i) {
197197
*score_iter = (counts[i] >= score_cutoff) ? static_cast<size_t>(counts[i]) : 0;
198198
score_iter++;
199199
});

0 commit comments

Comments
 (0)