SymSpell
SymSpell copied to clipboard
Possible optimization?
In the following function:
private HashSet<string> Edits(string word, int editDistance, HashSet<string> deleteWords)
{
editDistance++;
if (word.Length > 1)
{
for (int i = 0; i < word.Length; i++)
{
string delete = word.Remove(i, 1);
if (deleteWords.Add(delete))
{
//recursion, if maximum edit distance not yet reached
if (editDistance < maxDictionaryEditDistance) Edits(delete, editDistance, deleteWords);
}
}
}
return deleteWords;
}
Would it make sense to only add to calculate and add the words to deleteWords
if editDistance < maxDictionaryEditDistance
is true? That is quite a difference in loading dictionary performance. It does change the functionality, but isn't that the correct approach not to add the words anyhow?