Terraria ModLoader  0.11.1
A framework for Terraria mods
Terraria.ModLoader.Exceptions.LevenshteinDistance Class Reference

Static Public Member Functions

static int Compute (string s, string t)
 

Detailed Description

Definition at line 36 of file MissingResourceException.cs.

Member Function Documentation

◆ Compute()

static int Terraria.ModLoader.Exceptions.LevenshteinDistance.Compute ( string  s,
string  t 
)
static

Definition at line 93 of file MissingResourceException.cs.

93  {
94  int n = s.Length;
95  int m = t.Length;
96  int[,] d = new int[n + 1, m + 1];
97 
98  // Step 1
99  if (n == 0) {
100  return m;
101  }
102 
103  if (m == 0) {
104  return n;
105  }
106 
107  // Step 2
108  for (int i = 0; i <= n; d[i, 0] = i++) {
109  }
110 
111  for (int j = 0; j <= m; d[0, j] = j++) {
112  }
113 
114  // Step 3
115  for (int i = 1; i <= n; i++) {
116  //Step 4
117  for (int j = 1; j <= m; j++) {
118  // Step 5
119  int cost = (t[j - 1] == s[i - 1]) ? 0 : 2; // substitution
120 
121  // Step 6
122  d[i, j] = Math.Min(
123  Math.Min(d[i - 1, j] + 2, d[i, j - 1] + 2),
124  d[i - 1, j - 1] + cost);
125  }
126  }
127  // Step 7
128  return d[n, m];
129  }