7 #ifndef IG_OMW_ALGORITHM_H
8 #define IG_OMW_ALGORITHM_H
17 #include "../omw/int.h"
25 std::vector<uint8_t> doubleDabble128(uint32_t valueHH, uint32_t valueLH, uint32_t valueHL, uint32_t valueLL);
28 std::vector<uint8_t> doubleDabble128(uint64_t valueH, uint64_t valueL);
36 inline size_t levenshteinDistance(
const T* a,
size_t aCount,
const T* b,
size_t bCount)
42 std::vector<std::vector<size_t>> m(aCount + 1, std::vector<size_t>(bCount + 1, 0));
44 for (
size_t j = 1; j < m[0].size(); ++j) m[0][j] = j;
46 for (
size_t i = 1; i < m.size(); ++i)
50 for (
size_t j = 1; j < m[i].size(); ++j)
52 const size_t sub = m[i - 1][j - 1] + (*(a + i - 1) == *(b + j - 1) ? 0 : 1);
53 const size_t ins = m[i][j - 1] + 1;
54 const size_t del = m[i - 1][j] + 1;
56 m[i][j] = std::min(std::min(sub, ins), del);
60 r = m[aCount][bCount];
67 inline size_t levenshteinDistance(
const char* a,
const char* b)
70 if (a && b) r = levenshteinDistance(a, std::strlen(a), b, std::strlen(b));
75 inline size_t levenshteinDistance(
const std::string& a,
const std::string& b) {
return levenshteinDistance(a.data(), a.size(), b.data(), b.size()); }
78 inline size_t levenshteinDistance(
const std::vector<T>& a,
const std::vector<T>& b)
82 if (a.empty() && b.empty()) r = 0;
83 else if (a.empty()) r = levenshteinDistance<T>(b.data(), 0, b.data(), b.size());
84 else if (b.empty()) r = levenshteinDistance<T>(a.data(), a.size(), a.data(), 0);
85 else r = levenshteinDistance<T>(a.data(), a.size(), b.data(), b.size());
94 #endif // IG_OMW_ALGORITHM_H