Skip to content

Commit

Permalink
clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
Neargye committed Jan 23, 2024
1 parent 55592cc commit f7ad54f
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions SwipeType/TextDistance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;

namespace SwipeType
{
internal static class TextDistance
Expand All @@ -40,16 +38,16 @@ internal static int GetDamerauLevenshteinDistance(this string s, string t)

while ((sLen > 0) && (s[sLen - 1] == t[tLen - 1]))
{
sLen--;
tLen--;
--sLen;
--tLen;
}

int start = 0;
if ((s[0] == t[0]) || (sLen == 0))
{
while ((start < sLen) && (s[start] == t[start]))
{
start++;
++start;
}
sLen -= start;
tLen -= start;
Expand All @@ -64,22 +62,22 @@ internal static int GetDamerauLevenshteinDistance(this string s, string t)

var v0 = new int[tLen];
var v2 = new int[tLen];
for (int j = 0; j < tLen; j++)
for (int j = 0; j < tLen; ++j)
{
v0[j] = j + 1;
}

char sChar = s[0];
int current = 0;
for (int i = 0; i < sLen; i++)
for (int i = 0; i < sLen; ++i)
{
char prevsChar = sChar;
sChar = s[start + i];
char tChar = t[0];
int left = i;
current = i + 1;
int nextTransCost = 0;
for (int j = 0; j < tLen; j++)
for (int j = 0; j < tLen; ++j)
{
int above = current;
int thisTransCost = nextTransCost;
Expand All @@ -100,10 +98,10 @@ internal static int GetDamerauLevenshteinDistance(this string s, string t)
{
current = above;
}
current++;
++current;
if ((i != 0) && (j != 0) && (sChar == prevtChar) && (prevsChar == tChar))
{
thisTransCost++;
++thisTransCost;
if (thisTransCost < current)
{
current = thisTransCost;
Expand Down

0 comments on commit f7ad54f

Please sign in to comment.