-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch introduces a modified Damerau-Levenshtein algorithm into Git's code base, and uses it with the following penalties to show some similar commands when an unknown command was encountered: swap = 0, insertion = 1, substitution = 2, deletion = 4 A typical output would now look like this: $ git sm git: 'sm' is not a git-command. See 'git --help'. Did you mean one of these? am rm The cut-off is at similarity rating 6, which was empirically determined to give sensible results. As a convenience, if there is only one candidate, Git continues under the assumption that the user mistyped it. Example: $ git reabse WARNING: You called a Git program named 'reabse', which does not exist. Continuing under the assumption that you meant 'rebase' [...] Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
- Loading branch information
Johannes Schindelin
authored and
Junio C Hamano
committed
Aug 31, 2008
1 parent
a1184d8
commit 8af84da
Showing
7 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "cache.h" | ||
#include "levenshtein.h" | ||
|
||
int levenshtein(const char *string1, const char *string2, | ||
int w, int s, int a, int d) | ||
{ | ||
int len1 = strlen(string1), len2 = strlen(string2); | ||
int *row0 = xmalloc(sizeof(int) * (len2 + 1)); | ||
int *row1 = xmalloc(sizeof(int) * (len2 + 1)); | ||
int *row2 = xmalloc(sizeof(int) * (len2 + 1)); | ||
int i, j; | ||
|
||
for (j = 0; j <= len2; j++) | ||
row1[j] = j * a; | ||
for (i = 0; i < len1; i++) { | ||
int *dummy; | ||
|
||
row2[0] = (i + 1) * d; | ||
for (j = 0; j < len2; j++) { | ||
/* substitution */ | ||
row2[j + 1] = row1[j] + s * (string1[i] != string2[j]); | ||
/* swap */ | ||
if (i > 0 && j > 0 && string1[i - 1] == string2[j] && | ||
string1[i] == string2[j - 1] && | ||
row2[j + 1] > row0[j - 1] + w) | ||
row2[j + 1] = row0[j - 1] + w; | ||
/* deletion */ | ||
if (j + 1 < len2 && row2[j + 1] > row1[j + 1] + d) | ||
row2[j + 1] = row1[j + 1] + d; | ||
/* insertion */ | ||
if (row2[j + 1] > row2[j] + a) | ||
row2[j + 1] = row2[j] + a; | ||
} | ||
|
||
dummy = row0; | ||
row0 = row1; | ||
row1 = row2; | ||
row2 = dummy; | ||
} | ||
|
||
i = row1[len2]; | ||
free(row0); | ||
free(row1); | ||
free(row2); | ||
|
||
return i; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef LEVENSHTEIN_H | ||
#define LEVENSHTEIN_H | ||
|
||
int levenshtein(const char *string1, const char *string2, | ||
int swap_penalty, int substition_penalty, | ||
int insertion_penalty, int deletion_penalty); | ||
|
||
#endif |