Skip to content

Commit

Permalink
improve support for C++11
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbachmann committed Dec 25, 2024
1 parent 93603d5 commit c95fe98
Show file tree
Hide file tree
Showing 26 changed files with 233 additions and 145 deletions.
188 changes: 116 additions & 72 deletions extras/rapidfuzz_amalgamated.hpp

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions rapidfuzz/details/CharSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include <type_traits>
#include <unordered_set>

namespace rapidfuzz::detail {
namespace rapidfuzz {
namespace detail {

/*
* taken from https://stackoverflow.com/a/17251989/11335032
Expand Down Expand Up @@ -71,4 +72,5 @@ struct CharSet {
}
};

} // namespace rapidfuzz::detail
} // namespace detail
} // namespace rapidfuzz
6 changes: 4 additions & 2 deletions rapidfuzz/details/GrowingHashmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#include <stddef.h>
#include <stdint.h>

namespace rapidfuzz::detail {
namespace rapidfuzz {
namespace detail {

/* hashmap for integers which can only grow, but can't remove elements */
template <typename T_Key, typename T_Entry>
Expand Down Expand Up @@ -200,4 +201,5 @@ struct HybridGrowingHashmap {
std::array<value_type, 256> m_extendedAscii;
};

} // namespace rapidfuzz::detail
} // namespace detail
} // namespace rapidfuzz
6 changes: 4 additions & 2 deletions rapidfuzz/details/Matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include <stdio.h>
#include <vector>

namespace rapidfuzz::detail {
namespace rapidfuzz {
namespace detail {

template <typename T, bool IsConst>
struct BitMatrixView {
Expand Down Expand Up @@ -196,4 +197,5 @@ struct ShiftedBitMatrix {
std::vector<ptrdiff_t> m_offsets;
};

} // namespace rapidfuzz::detail
} // namespace detail
} // namespace rapidfuzz
6 changes: 4 additions & 2 deletions rapidfuzz/details/PatternMatchVector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#include <rapidfuzz/details/Range.hpp>
#include <rapidfuzz/details/intrinsics.hpp>

namespace rapidfuzz::detail {
namespace rapidfuzz {
namespace detail {

struct BitvectorHashmap {
BitvectorHashmap() : m_map()
Expand Down Expand Up @@ -219,4 +220,5 @@ struct BlockPatternMatchVector {
BitMatrix<uint64_t> m_extendedAscii;
};

} // namespace rapidfuzz::detail
} // namespace detail
} // namespace rapidfuzz
14 changes: 8 additions & 6 deletions rapidfuzz/details/Range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#include <sys/types.h>
#include <vector>

namespace rapidfuzz::detail {
namespace rapidfuzz {
namespace detail {

static inline void assume(bool b)
{
Expand Down Expand Up @@ -117,10 +118,10 @@ class Range {
return !empty();
}

template <
typename... Dummy, typename IterCopy = Iter,
typename = std::enable_if_t<std::is_base_of_v<
std::random_access_iterator_tag, typename std::iterator_traits<IterCopy>::iterator_category>>>
template <typename... Dummy, typename IterCopy = Iter,
typename = std::enable_if_t<
std::is_base_of<std::random_access_iterator_tag,
typename std::iterator_traits<IterCopy>::iterator_category>::value>>
constexpr decltype(auto) operator[](size_t n) const
{
return _first[static_cast<ptrdiff_t>(n)];
Expand Down Expand Up @@ -215,4 +216,5 @@ inline bool operator>=(const Range<InputIt1>& a, const Range<InputIt2>& b)
template <typename InputIt>
using RangeVec = std::vector<Range<InputIt>>;

} // namespace rapidfuzz::detail
} // namespace detail
} // namespace rapidfuzz
8 changes: 5 additions & 3 deletions rapidfuzz/details/SplittedSentenceView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
#include <rapidfuzz/details/Range.hpp>
#include <rapidfuzz/details/type_traits.hpp>

namespace rapidfuzz::detail {
namespace rapidfuzz {
namespace detail {

template <typename InputIt>
class SplittedSentenceView {
public:
using CharT = iter_value_t<InputIt>;

SplittedSentenceView(RangeVec<InputIt> sentence) noexcept(
std::is_nothrow_move_constructible_v<RangeVec<InputIt>>)
std::is_nothrow_move_constructible<RangeVec<InputIt>>::value)
: m_sentence(std::move(sentence))
{}

Expand Down Expand Up @@ -83,4 +84,5 @@ auto SplittedSentenceView<InputIt>::join() const -> std::vector<CharT>
return joined;
}

} // namespace rapidfuzz::detail
} // namespace detail
} // namespace rapidfuzz
6 changes: 4 additions & 2 deletions rapidfuzz/details/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
# include <mm_malloc.h>
#endif

namespace rapidfuzz::detail {
namespace rapidfuzz {
namespace detail {

template <typename InputIt1, typename InputIt2, typename InputIt3>
struct DecomposedSet {
Expand Down Expand Up @@ -94,6 +95,7 @@ static inline void rf_aligned_free(void* ptr)

/**@}*/

} // namespace rapidfuzz::detail
} // namespace detail
} // namespace rapidfuzz

#include <rapidfuzz/details/common_impl.hpp>
6 changes: 4 additions & 2 deletions rapidfuzz/details/common_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#include <array>
#include <iterator>

namespace rapidfuzz::detail {
namespace rapidfuzz {
namespace detail {

template <typename InputIt1, typename InputIt2>
DecomposedSet<InputIt1, InputIt2, InputIt1> set_decomposition(SplittedSentenceView<InputIt1> a,
Expand Down Expand Up @@ -169,4 +170,5 @@ SplittedSentenceView<InputIt> sorted_split(InputIt first, InputIt last)
return SplittedSentenceView<InputIt>(splitted);
}

} // namespace rapidfuzz::detail
} // namespace detail
} // namespace rapidfuzz
42 changes: 22 additions & 20 deletions rapidfuzz/details/distance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
#include <rapidfuzz/details/simd.hpp>
#include <type_traits>

namespace rapidfuzz::detail {
namespace rapidfuzz {
namespace detail {

template <typename T, typename... Args>
struct NormalizedMetricBase {
template <typename InputIt1, typename InputIt2,
typename = std::enable_if_t<!std::is_same_v<InputIt2, double>>>
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
static double normalized_distance(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2,
Args... args, double score_cutoff, double score_hint)
{
Expand All @@ -31,7 +32,7 @@ struct NormalizedMetricBase {
}

template <typename InputIt1, typename InputIt2,
typename = std::enable_if_t<!std::is_same_v<InputIt2, double>>>
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
static double normalized_similarity(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2,
Args... args, double score_cutoff, double score_hint)
{
Expand Down Expand Up @@ -82,7 +83,7 @@ struct NormalizedMetricBase {
template <typename T, typename ResType, int64_t WorstSimilarity, int64_t WorstDistance, typename... Args>
struct DistanceBase : public NormalizedMetricBase<T, Args...> {
template <typename InputIt1, typename InputIt2,
typename = std::enable_if_t<!std::is_same_v<InputIt2, double>>>
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
static ResType distance(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Args... args,
ResType score_cutoff, ResType score_hint)
{
Expand All @@ -98,7 +99,7 @@ struct DistanceBase : public NormalizedMetricBase<T, Args...> {
}

template <typename InputIt1, typename InputIt2,
typename = std::enable_if_t<!std::is_same_v<InputIt2, double>>>
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
static ResType similarity(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Args... args,
ResType score_cutoff, ResType score_hint)
{
Expand Down Expand Up @@ -137,7 +138,7 @@ struct DistanceBase : public NormalizedMetricBase<T, Args...> {
template <typename T, typename ResType, int64_t WorstSimilarity, int64_t WorstDistance, typename... Args>
struct SimilarityBase : public NormalizedMetricBase<T, Args...> {
template <typename InputIt1, typename InputIt2,
typename = std::enable_if_t<!std::is_same_v<InputIt2, double>>>
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
static ResType distance(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Args... args,
ResType score_cutoff, ResType score_hint)
{
Expand All @@ -153,7 +154,7 @@ struct SimilarityBase : public NormalizedMetricBase<T, Args...> {
}

template <typename InputIt1, typename InputIt2,
typename = std::enable_if_t<!std::is_same_v<InputIt2, double>>>
typename = std::enable_if_t<!std::is_same<InputIt2, double>::value>>
static ResType similarity(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, Args... args,
ResType score_cutoff, ResType score_hint)
{
Expand Down Expand Up @@ -184,15 +185,15 @@ struct SimilarityBase : public NormalizedMetricBase<T, Args...> {
}

template <typename U>
static std::enable_if_t<std::is_floating_point_v<U>, U> _apply_distance_score_cutoff(U score,
U score_cutoff)
static std::enable_if_t<std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
U score_cutoff)
{
return (score <= score_cutoff) ? score : 1.0;
}

template <typename U>
static std::enable_if_t<!std::is_floating_point_v<U>, U> _apply_distance_score_cutoff(U score,
U score_cutoff)
static std::enable_if_t<!std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
U score_cutoff)
{
return (score <= score_cutoff) ? score : score_cutoff + 1;
}
Expand Down Expand Up @@ -364,15 +365,15 @@ struct CachedSimilarityBase : public CachedNormalizedMetricBase<T> {
}

template <typename U>
static std::enable_if_t<std::is_floating_point_v<U>, U> _apply_distance_score_cutoff(U score,
U score_cutoff)
static std::enable_if_t<std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
U score_cutoff)
{
return (score <= score_cutoff) ? score : 1.0;
}

template <typename U>
static std::enable_if_t<!std::is_floating_point_v<U>, U> _apply_distance_score_cutoff(U score,
U score_cutoff)
static std::enable_if_t<!std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
U score_cutoff)
{
return (score <= score_cutoff) ? score : score_cutoff + 1;
}
Expand Down Expand Up @@ -558,15 +559,15 @@ struct MultiSimilarityBase : public MultiNormalizedMetricBase<T, ResType> {
}

template <typename U>
static std::enable_if_t<std::is_floating_point_v<U>, U> _apply_distance_score_cutoff(U score,
U score_cutoff)
static std::enable_if_t<std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
U score_cutoff)
{
return (score <= score_cutoff) ? score : 1.0;
}

template <typename U>
static std::enable_if_t<!std::is_floating_point_v<U>, U> _apply_distance_score_cutoff(U score,
U score_cutoff)
static std::enable_if_t<!std::is_floating_point<U>::value, U> _apply_distance_score_cutoff(U score,
U score_cutoff)
{
return (score <= score_cutoff) ? score : score_cutoff + 1;
}
Expand All @@ -576,4 +577,5 @@ struct MultiSimilarityBase : public MultiNormalizedMetricBase<T, ResType> {
friend T;
};

} // namespace rapidfuzz::detail
} // namespace detail
} // namespace rapidfuzz
6 changes: 4 additions & 2 deletions rapidfuzz/details/intrinsics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# include <intrin.h>
#endif

namespace rapidfuzz::detail {
namespace rapidfuzz {
namespace detail {

template <typename T>
T bit_mask_lsb(size_t n)
Expand Down Expand Up @@ -209,4 +210,5 @@ constexpr void unroll(F&& f)
unroll_impl(std::make_integer_sequence<T, count>{}, std::forward<F>(f));
}

} // namespace rapidfuzz::detail
} // namespace detail
} // namespace rapidfuzz
6 changes: 4 additions & 2 deletions rapidfuzz/distance/DamerauLevenshtein_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#include <rapidfuzz/details/common.hpp>
#include <rapidfuzz/details/distance.hpp>

namespace rapidfuzz::detail {
namespace rapidfuzz {
namespace detail {

template <typename IntType>
struct RowId {
Expand Down Expand Up @@ -137,4 +138,5 @@ class DamerauLevenshtein
}
};

} // namespace rapidfuzz::detail
} // namespace detail
} // namespace rapidfuzz
6 changes: 4 additions & 2 deletions rapidfuzz/distance/Hamming_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#include <rapidfuzz/details/distance.hpp>
#include <stdexcept>

namespace rapidfuzz::detail {
namespace rapidfuzz {
namespace detail {

class Hamming : public DistanceBase<Hamming, size_t, 0, std::numeric_limits<int64_t>::max(), bool> {
friend DistanceBase<Hamming, size_t, 0, std::numeric_limits<int64_t>::max(), bool>;
Expand Down Expand Up @@ -57,4 +58,5 @@ Editops hamming_editops(const Range<InputIt1>& s1, const Range<InputIt2>& s2, bo
return ops;
}

} // namespace rapidfuzz::detail
} // namespace detail
} // namespace rapidfuzz
6 changes: 4 additions & 2 deletions rapidfuzz/distance/Indel_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include <rapidfuzz/details/intrinsics.hpp>
#include <rapidfuzz/distance/LCSseq.hpp>

namespace rapidfuzz::detail {
namespace rapidfuzz {
namespace detail {

template <typename InputIt1, typename InputIt2>
size_t indel_distance(const BlockPatternMatchVector& block, const Range<InputIt1>& s1,
Expand Down Expand Up @@ -65,4 +66,5 @@ class Indel : public DistanceBase<Indel, size_t, 0, std::numeric_limits<int64_t>
}
};

} // namespace rapidfuzz::detail
} // namespace detail
} // namespace rapidfuzz
Loading

0 comments on commit c95fe98

Please sign in to comment.