findLevenshteinDistance function
Implementation
FindLevenshteinDistanceResult? findLevenshteinDistance(
String password,
Map<String, int> rankedDictionary,
int threshold,
) {
try {
int foundDistance = 0;
String found = rankedDictionary.keys.firstWhere((entry) {
final usedThreshold = getUsedThreshold(password, entry, threshold);
if ((password.length - entry.length).abs() > usedThreshold) {
return false;
}
final foundEntryDistance = levenshtein(password, entry);
final isInThreshold = foundEntryDistance <= usedThreshold;
if (isInThreshold) {
foundDistance = foundEntryDistance;
}
return isInThreshold;
});
return FindLevenshteinDistanceResult(
levenshteinDistance: foundDistance,
levenshteinDistanceEntry: found,
);
} on StateError {
return null;
}
}