11 #ifndef TLX_STRING_LEVENSHTEIN_HEADER 12 #define TLX_STRING_LEVENSHTEIN_HEADER 36 static inline bool char_equal(
const char& a,
const char& b)
48 static inline bool char_equal(
const char& a,
const char& b)
65 template <
typename Param>
68 const char* b,
size_t b_size) {
71 if (a_size == 0)
return b_size * Param::cost_insert_delete;
72 if (b_size == 0)
return a_size * Param::cost_insert_delete;
75 if (a_size < b_size) {
85 for (
size_t i = 0; i < a_size + 1; i++) {
90 for (
size_t j = 1; j < b_size + 1; j++)
98 for (
size_t i = 1; i < a_size + 1; i++)
104 thisrow[i - 1] + Param::cost_insert_delete,
106 lastrow[i] + Param::cost_insert_delete),
109 Param::char_equal(a[i - 1], b[j - 1])
110 ? 0 : Param::cost_replace)
116 return thisrow[a_size];
129 return levenshtein_algorithm<LevenshteinStandardParameters>(
130 a, std::strlen(a), b, std::strlen(b));
143 return levenshtein_algorithm<LevenshteinStandardICaseParameters>(
144 a, std::strlen(a), b, std::strlen(b));
156 static inline size_t levenshtein(
const std::string& a,
const std::string& b) {
157 return levenshtein_algorithm<LevenshteinStandardParameters>(
158 a.data(), a.size(), b.data(), b.size());
172 return levenshtein_algorithm<LevenshteinStandardICaseParameters>(
173 a.data(), a.size(), b.data(), b.size());
180 #endif // !TLX_STRING_LEVENSHTEIN_HEADER static size_t levenshtein_icase(const char *a, const char *b)
Computes the Levenshtein string distance between two strings.
static size_t levenshtein(const char *a, const char *b)
Computes the Levenshtein string distance between two strings.
char to_lower(char ch)
Transform the given character to lower case without any localization.
Simpler non-growing vector without initialization.
Standard parameters to levenshtein distance function.
static uint32_t min(uint32_t x, uint32_t y)
void swap(CountingPtr< A, D > &a1, CountingPtr< A, D > &a2) noexcept
swap enclosed object with another counting pointer (no reference counts need change) ...
static const unsigned int cost_replace
static bool char_equal(const char &a, const char &b)
static const unsigned int cost_insert_delete
static bool char_equal(const char &a, const char &b)
static size_t levenshtein_algorithm(const char *a, size_t a_size, const char *b, size_t b_size)
Computes the Levenshtein string distance also called edit distance between two strings.
Standard parameters to Levenshtein distance function.