mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Enable Damerau-Levenshtein
This commit is contained in:
+12
-1
@@ -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 levenstein_distance_case_insensitive(String const &a, String const &b) {
|
||||||
isize w = a.len+1;
|
isize w = a.len+1;
|
||||||
@@ -1206,6 +1207,16 @@ isize levenstein_distance_case_insensitive(String const &a, String const &b) {
|
|||||||
if (substitute < minimum) {
|
if (substitute < minimum) {
|
||||||
minimum = substitute;
|
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;
|
matrix[i*w + j] = minimum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1225,7 +1236,7 @@ struct DidYouMeanAnswers {
|
|||||||
String key;
|
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 did_you_mean_make(gbAllocator allocator, isize cap, String const &key) {
|
||||||
DidYouMeanAnswers d = {};
|
DidYouMeanAnswers d = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user