Skip to content

Commit 9c3ac35

Browse files
committed
fix compiler errors
1 parent 21fc816 commit 9c3ac35

File tree

12 files changed

+216
-67
lines changed

12 files changed

+216
-67
lines changed

extras/rapidfuzz_amalgamated.hpp

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
22
// SPDX-License-Identifier: MIT
33
// RapidFuzz v1.0.2
4-
// Generated: 2022-09-03 19:36:32.122526
4+
// Generated: 2022-09-03 21:47:43.168879
55
// ----------------------------------------------------------
66
// This file is an amalgamation of multiple different files.
77
// You probably shouldn't edit it directly.
88
// ----------------------------------------------------------
99
#ifndef RAPIDFUZZ_AMALGAMATED_HPP_INCLUDED
1010
#define RAPIDFUZZ_AMALGAMATED_HPP_INCLUDED
1111

12+
#include <algorithm>
1213
#include <cmath>
1314

1415
#include <cassert>
@@ -34,11 +35,10 @@ struct GrowingHashmap {
3435
using size_type = unsigned int;
3536

3637
private:
37-
static constexpr value_type _empty_val = value_type();
3838
static constexpr size_type min_size = 8;
3939
struct MapElem {
4040
key_type key;
41-
value_type value = _empty_val;
41+
value_type value = value_type();
4242
};
4343

4444
int used;
@@ -95,7 +95,7 @@ struct GrowingHashmap {
9595

9696
value_type get(key_type key) const noexcept
9797
{
98-
if (m_map == NULL) return _empty_val;
98+
if (m_map == NULL) return value_type();
9999

100100
return m_map[lookup(key)].value;
101101
}
@@ -106,7 +106,7 @@ struct GrowingHashmap {
106106

107107
size_t i = lookup(key);
108108

109-
if (m_map[i].value == _empty_val) {
109+
if (m_map[i].value == value_type()) {
110110
/* resize when 2/3 full */
111111
if (++fill * 3 >= (mask + 1) * 2) {
112112
grow((used + 1) * 2);
@@ -136,12 +136,12 @@ struct GrowingHashmap {
136136
size_t hash = static_cast<size_t>(key);
137137
size_t i = hash & static_cast<size_t>(mask);
138138

139-
if (m_map[i].value == _empty_val || m_map[i].key == key) return i;
139+
if (m_map[i].value == value_type() || m_map[i].key == key) return i;
140140

141141
size_t perturb = hash;
142142
while (true) {
143143
i = (i * 5 + perturb + 1) & static_cast<size_t>(mask);
144-
if (m_map[i].value == _empty_val || m_map[i].key == key) return i;
144+
if (m_map[i].value == value_type() || m_map[i].key == key) return i;
145145

146146
perturb >>= 5;
147147
}
@@ -160,7 +160,7 @@ struct GrowingHashmap {
160160
mask = newSize - 1;
161161

162162
for (int i = 0; used > 0; i++)
163-
if (oldMap[i].value != _empty_val) {
163+
if (oldMap[i].value != value_type()) {
164164
size_t j = lookup(oldMap[i].key);
165165

166166
m_map[j].key = oldMap[i].key;
@@ -382,9 +382,9 @@ struct BitMatrix {
382382
} // namespace detail
383383
} // namespace rapidfuzz
384384

385-
#include <iostream>
386385
#include <iterator>
387386
#include <limits>
387+
#include <ostream>
388388
#include <stdexcept>
389389
#include <vector>
390390

@@ -2249,6 +2249,20 @@ struct CachedSimilarityBase : public CachedNormalizedMetricBase<T> {
22492249
namespace rapidfuzz {
22502250
namespace detail {
22512251

2252+
template <typename IntType>
2253+
struct RowId {
2254+
IntType val = -1;
2255+
friend bool operator==(const RowId& lhs, const RowId& rhs)
2256+
{
2257+
return lhs.val == rhs.val;
2258+
}
2259+
2260+
friend bool operator!=(const RowId& lhs, const RowId& rhs)
2261+
{
2262+
return !(lhs == rhs);
2263+
}
2264+
};
2265+
22522266
/*
22532267
* based on the paper
22542268
* "Linear space string correction algorithm using the Damerau-Levenshtein distance"
@@ -2262,20 +2276,7 @@ int64_t damerau_levenshtein_distance_zhao(Range<InputIt1> s1, Range<InputIt2> s2
22622276
IntType maxVal = static_cast<IntType>(std::max(len1, len2) + 1);
22632277
assert(std::numeric_limits<IntType>::max() > maxVal);
22642278

2265-
struct RowId {
2266-
IntType val = -1;
2267-
bool operator==(const RowId& other)
2268-
{
2269-
return val == other.val;
2270-
}
2271-
2272-
bool operator!=(const RowId& other)
2273-
{
2274-
return !(*this == other);
2275-
}
2276-
};
2277-
2278-
HybridGrowingHashmap<typename Range<InputIt1>::value_type, RowId> last_row_id;
2279+
HybridGrowingHashmap<typename Range<InputIt1>::value_type, RowId<IntType>> last_row_id;
22792280
size_t size = static_cast<size_t>(s2.size() + 2);
22802281
assume(size != 0);
22812282
std::vector<IntType> FR_arr(size, maxVal);
@@ -2489,7 +2490,7 @@ struct CachedDamerauLevenshtein : public detail::CachedDistanceBase<CachedDamera
24892490
template <typename InputIt2>
24902491
int64_t maximum(detail::Range<InputIt2> s2) const
24912492
{
2492-
return std::max(static_cast<int64_t>(s1.size()), s2.size());
2493+
return std::max(static_cast<ptrdiff_t>(s1.size()), s2.size());
24932494
}
24942495

24952496
template <typename InputIt2>
@@ -3292,6 +3293,7 @@ class LCSseq : public SimilarityBase<LCSseq> {
32923293
} // namespace detail
32933294
} // namespace rapidfuzz
32943295

3296+
#include <algorithm>
32953297
#include <cmath>
32963298
#include <limits>
32973299

@@ -3379,7 +3381,7 @@ struct CachedLCSseq : detail::CachedSimilarityBase<CachedLCSseq<CharT1>> {
33793381
template <typename InputIt2>
33803382
int64_t maximum(detail::Range<InputIt2> s2) const
33813383
{
3382-
return std::max(static_cast<int64_t>(s1.size()), s2.size());
3384+
return std::max(static_cast<ptrdiff_t>(s1.size()), s2.size());
33833385
}
33843386

33853387
template <typename InputIt2>
@@ -3481,7 +3483,7 @@ template <typename InputIt1, typename InputIt2>
34813483
int64_t indel_similarity(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2,
34823484
int64_t score_cutoff = 0.0)
34833485
{
3484-
return detail::Indel::normalized_distance(first1, last1, first2, last2, score_cutoff);
3486+
return detail::Indel::similarity(first1, last1, first2, last2, score_cutoff);
34853487
}
34863488

34873489
template <typename Sentence1, typename Sentence2>

rapidfuzz/details/GrowingHashmap.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ struct GrowingHashmap {
1919
using size_type = unsigned int;
2020

2121
private:
22-
static constexpr value_type _empty_val = value_type();
2322
static constexpr size_type min_size = 8;
2423
struct MapElem {
2524
key_type key;
26-
value_type value = _empty_val;
25+
value_type value = value_type();
2726
};
2827

2928
int used;
@@ -80,7 +79,7 @@ struct GrowingHashmap {
8079

8180
value_type get(key_type key) const noexcept
8281
{
83-
if (m_map == NULL) return _empty_val;
82+
if (m_map == NULL) return value_type();
8483

8584
return m_map[lookup(key)].value;
8685
}
@@ -91,7 +90,7 @@ struct GrowingHashmap {
9190

9291
size_t i = lookup(key);
9392

94-
if (m_map[i].value == _empty_val) {
93+
if (m_map[i].value == value_type()) {
9594
/* resize when 2/3 full */
9695
if (++fill * 3 >= (mask + 1) * 2) {
9796
grow((used + 1) * 2);
@@ -121,12 +120,12 @@ struct GrowingHashmap {
121120
size_t hash = static_cast<size_t>(key);
122121
size_t i = hash & static_cast<size_t>(mask);
123122

124-
if (m_map[i].value == _empty_val || m_map[i].key == key) return i;
123+
if (m_map[i].value == value_type() || m_map[i].key == key) return i;
125124

126125
size_t perturb = hash;
127126
while (true) {
128127
i = (i * 5 + perturb + 1) & static_cast<size_t>(mask);
129-
if (m_map[i].value == _empty_val || m_map[i].key == key) return i;
128+
if (m_map[i].value == value_type() || m_map[i].key == key) return i;
130129

131130
perturb >>= 5;
132131
}
@@ -145,7 +144,7 @@ struct GrowingHashmap {
145144
mask = newSize - 1;
146145

147146
for (int i = 0; used > 0; i++)
148-
if (oldMap[i].value != _empty_val) {
147+
if (oldMap[i].value != value_type()) {
149148
size_t j = lookup(oldMap[i].key);
150149

151150
m_map[j].key = oldMap[i].key;

rapidfuzz/details/Range.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
#pragma once
55

6-
#include <iostream>
76
#include <iterator>
87
#include <limits>
8+
#include <ostream>
99
#include <stdexcept>
1010
#include <vector>
1111

rapidfuzz/distance/DamerauLevenshtein.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* SPDX-License-Identifier: MIT */
22
/* Copyright © 2022-present Max Bachmann */
33

4+
#include <algorithm>
45
#include <cmath>
56
#include <rapidfuzz/distance/DamerauLevenshtein_impl.hpp>
67

@@ -125,7 +126,7 @@ struct CachedDamerauLevenshtein : public detail::CachedDistanceBase<CachedDamera
125126
template <typename InputIt2>
126127
int64_t maximum(detail::Range<InputIt2> s2) const
127128
{
128-
return std::max(static_cast<int64_t>(s1.size()), s2.size());
129+
return std::max(static_cast<ptrdiff_t>(s1.size()), s2.size());
129130
}
130131

131132
template <typename InputIt2>

rapidfuzz/distance/DamerauLevenshtein_impl.hpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@
1616
namespace rapidfuzz {
1717
namespace detail {
1818

19+
template <typename IntType>
20+
struct RowId {
21+
IntType val = -1;
22+
friend bool operator==(const RowId& lhs, const RowId& rhs)
23+
{
24+
return lhs.val == rhs.val;
25+
}
26+
27+
friend bool operator!=(const RowId& lhs, const RowId& rhs)
28+
{
29+
return !(lhs == rhs);
30+
}
31+
};
32+
1933
/*
2034
* based on the paper
2135
* "Linear space string correction algorithm using the Damerau-Levenshtein distance"
@@ -29,20 +43,7 @@ int64_t damerau_levenshtein_distance_zhao(Range<InputIt1> s1, Range<InputIt2> s2
2943
IntType maxVal = static_cast<IntType>(std::max(len1, len2) + 1);
3044
assert(std::numeric_limits<IntType>::max() > maxVal);
3145

32-
struct RowId {
33-
IntType val = -1;
34-
bool operator==(const RowId& other)
35-
{
36-
return val == other.val;
37-
}
38-
39-
bool operator!=(const RowId& other)
40-
{
41-
return !(*this == other);
42-
}
43-
};
44-
45-
HybridGrowingHashmap<typename Range<InputIt1>::value_type, RowId> last_row_id;
46+
HybridGrowingHashmap<typename Range<InputIt1>::value_type, RowId<IntType>> last_row_id;
4647
size_t size = static_cast<size_t>(s2.size() + 2);
4748
assume(size != 0);
4849
std::vector<IntType> FR_arr(size, maxVal);

rapidfuzz/distance/Indel.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ template <typename InputIt1, typename InputIt2>
2626
int64_t indel_similarity(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2,
2727
int64_t score_cutoff = 0.0)
2828
{
29-
return detail::Indel::normalized_distance(first1, last1, first2, last2, score_cutoff);
29+
return detail::Indel::similarity(first1, last1, first2, last2, score_cutoff);
3030
}
3131

3232
template <typename Sentence1, typename Sentence2>

rapidfuzz/distance/LCSseq.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#pragma once
55
#include <rapidfuzz/distance/LCSseq_impl.hpp>
66

7+
#include <algorithm>
78
#include <cmath>
89
#include <limits>
910

@@ -91,7 +92,7 @@ struct CachedLCSseq : detail::CachedSimilarityBase<CachedLCSseq<CharT1>> {
9192
template <typename InputIt2>
9293
int64_t maximum(detail::Range<InputIt2> s2) const
9394
{
94-
return std::max(static_cast<int64_t>(s1.size()), s2.size());
95+
return std::max(static_cast<ptrdiff_t>(s1.size()), s2.size());
9596
}
9697

9798
template <typename InputIt2>

test/distance/tests-DamerauLevenshtein.cpp

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,45 @@ int64_t damerau_levenshtein_distance(const Sentence1& s1, const Sentence2& s2,
2222
int64_t max = std::numeric_limits<int64_t>::max())
2323
{
2424
int64_t res1 = rapidfuzz::experimental::damerau_levenshtein_distance(s1, s2, max);
25+
int64_t res2 = rapidfuzz::experimental::damerau_levenshtein_distance(s1.begin(), s1.end(), s2.begin(),
26+
s2.end(), max);
2527
rapidfuzz::experimental::CachedDamerauLevenshtein<typename Sentence1::value_type> scorer(s1);
26-
int64_t res2 = scorer.distance(s2, max);
28+
int64_t res3 = scorer.distance(s2, max);
29+
int64_t res4 = scorer.distance(s2.begin(), s2.end(), max);
2730
REQUIRE(res1 == res2);
31+
REQUIRE(res1 == res3);
32+
REQUIRE(res1 == res4);
33+
return res1;
34+
}
35+
36+
template <typename Sentence1, typename Sentence2>
37+
int64_t damerau_levenshtein_similarity(const Sentence1& s1, const Sentence2& s2, int64_t max = 0)
38+
{
39+
int64_t res1 = rapidfuzz::experimental::damerau_levenshtein_similarity(s1, s2, max);
40+
int64_t res2 = rapidfuzz::experimental::damerau_levenshtein_similarity(s1.begin(), s1.end(), s2.begin(),
41+
s2.end(), max);
42+
rapidfuzz::experimental::CachedDamerauLevenshtein<typename Sentence1::value_type> scorer(s1);
43+
int64_t res3 = scorer.similarity(s2, max);
44+
int64_t res4 = scorer.similarity(s2.begin(), s2.end(), max);
45+
REQUIRE(res1 == res2);
46+
REQUIRE(res1 == res3);
47+
REQUIRE(res1 == res4);
48+
return res1;
49+
}
50+
51+
template <typename Sentence1, typename Sentence2>
52+
double damerau_levenshtein_normalized_distance(const Sentence1& s1, const Sentence2& s2,
53+
double score_cutoff = 1.0)
54+
{
55+
double res1 = rapidfuzz::experimental::damerau_levenshtein_normalized_distance(s1, s2, score_cutoff);
56+
double res2 = rapidfuzz::experimental::damerau_levenshtein_normalized_distance(
57+
s1.begin(), s1.end(), s2.begin(), s2.end(), score_cutoff);
58+
rapidfuzz::experimental::CachedDamerauLevenshtein<typename Sentence1::value_type> scorer(s1);
59+
double res3 = scorer.normalized_distance(s2, score_cutoff);
60+
double res4 = scorer.normalized_distance(s2.begin(), s2.end(), score_cutoff);
61+
REQUIRE(res1 == Catch::Approx(res2).epsilon(0.0001));
62+
REQUIRE(res1 == Catch::Approx(res3).epsilon(0.0001));
63+
REQUIRE(res1 == Catch::Approx(res4).epsilon(0.0001));
2864
return res1;
2965
}
3066

@@ -33,9 +69,14 @@ double damerau_levenshtein_normalized_similarity(const Sentence1& s1, const Sent
3369
double score_cutoff = 0.0)
3470
{
3571
double res1 = rapidfuzz::experimental::damerau_levenshtein_normalized_similarity(s1, s2, score_cutoff);
72+
double res2 = rapidfuzz::experimental::damerau_levenshtein_normalized_similarity(
73+
s1.begin(), s1.end(), s2.begin(), s2.end(), score_cutoff);
3674
rapidfuzz::experimental::CachedDamerauLevenshtein<typename Sentence1::value_type> scorer(s1);
37-
double res2 = scorer.normalized_similarity(s2, score_cutoff);
75+
double res3 = scorer.normalized_similarity(s2, score_cutoff);
76+
double res4 = scorer.normalized_similarity(s2.begin(), s2.end(), score_cutoff);
3877
REQUIRE(res1 == Catch::Approx(res2).epsilon(0.0001));
78+
REQUIRE(res1 == Catch::Approx(res3).epsilon(0.0001));
79+
REQUIRE(res1 == Catch::Approx(res4).epsilon(0.0001));
3980
return res1;
4081
}
4182

0 commit comments

Comments
 (0)