diff options
| author | gingerBill <bill@gingerbill.org> | 2021-07-10 11:09:24 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-07-10 11:09:24 +0100 |
| commit | 141573c18cba4ecde552fec53d73c74f854e2b8b (patch) | |
| tree | 85e892f468ecf978be0475617c9d10048d20f3f9 /src/common.cpp | |
| parent | e692efbe097ebb3fc7925620e0dc4fd736d67ee4 (diff) | |
Enable Damerau-Levenshtein
Diffstat (limited to 'src/common.cpp')
| -rw-r--r-- | src/common.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/common.cpp b/src/common.cpp index 9dfd694f4..a77051711 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -1177,6 +1177,7 @@ ReadDirectoryError read_directory(String path, Array<FileInfo> *fi) { +#define USE_DAMERAU_LEVENSHTEIN 1 isize levenstein_distance_case_insensitive(String const &a, String const &b) { isize w = a.len+1; @@ -1206,6 +1207,16 @@ isize levenstein_distance_case_insensitive(String const &a, String const &b) { if (substitute < minimum) { minimum = substitute; } + // Damerau-Levenshtein (transposition extension) + #if USE_DAMERAU_LEVENSHTEIN + if (i > 1 && j > 1) { + isize transpose = matrix[(i-2)*w + j-2] + 1; + if (transpose < minimum) { + minimum = transpose; + } + } + #endif + matrix[i*w + j] = minimum; } } @@ -1225,7 +1236,7 @@ struct DidYouMeanAnswers { String key; }; -enum {MAX_SMALLEST_DID_YOU_MEAN_DISTANCE = 3}; +enum {MAX_SMALLEST_DID_YOU_MEAN_DISTANCE = 3-USE_DAMERAU_LEVENSHTEIN}; DidYouMeanAnswers did_you_mean_make(gbAllocator allocator, isize cap, String const &key) { DidYouMeanAnswers d = {}; |