/** * Перебирает все слова в словаре с заданным хешем, записывая в результат только слова, удоволетворяющие ограничению * при данной метрике. */ private void Populate(String query, int queryHash, HashSet <Int32> set) { int[] hashBucket = hashTable[queryHash]; if (hashBucket != null) { foreach (int dictionaryIndex in hashBucket) { String word = dictionary[dictionaryIndex]; if (metric.GetDistance(query, word, maxDistance) <= maxDistance) { set.Add(dictionaryIndex); } } } }
public HashSet <Int32> Search(String str) { var set = new HashSet <Int32>(); for (int i = 0; i < str.Length - n + 1; ++i) { int ngram = NGramIndexer.GetNGram(alphabet, str, i, n); int[] dictIndexes = ngramMap[ngram]; if (dictIndexes != null) { foreach (var k in dictIndexes) { DLDistance d = new DLDistance(DEFAULT_LENGTH); int distance = d.GetDistance(dictionary[k], str, maxDistance, prefix); if (distance <= maxDistance) { set.Add(k); } } } } return(set); }