Skip to content

Commit

Permalink
Minor optimization for substitution candidate creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlexSee committed Oct 23, 2018
1 parent fba5034 commit 3ecf914
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions related/neighborhood.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@ float runHammingK1(const unordered_set<string> &wordSet, const vector<string> &p
// This search assumes k = 1.
for (size_t i = 0; i < pattern.size(); ++i)
{
string candidate = pattern;

for (const char c : alphabet)
{
if (pattern[i] == c)
{
continue;
}

string candidate = pattern;
candidate[i] = c;

if (wordSet.find(candidate) != wordSet.end())
Expand Down Expand Up @@ -145,14 +146,15 @@ float runLevenK1(const unordered_set<string> &wordSet, const vector<string> &pat
// Substitutions for k = 1.
for (size_t i = 0; i < pattern.size(); ++i)
{
string candidate = pattern;

for (const char c : alphabet)
{
if (pattern[i] == c)
{
continue;
}

string candidate = pattern;
candidate[i] = c;

if (wordSet.find(candidate) != wordSet.end())
Expand Down

0 comments on commit 3ecf914

Please sign in to comment.