Example #1
0
        private static void GetWords(TrieNode parentNode, List <KeyValuePair <string, int> > result, string prefix)
        {
            if (parentNode.Children == null)
            {
                return;
            }

            foreach (var node in parentNode.Children)
            {
                if (node.Element.CharKey.Equals(EndOfWordElement))
                {
                    var newItem  = new KeyValuePair <string, int>(prefix, node.Element.Frequency);
                    var position = BinarySearch.BinarySearchForStringWithFrequency(result, newItem);

                    if (position >= WithSamePrefixWordMaxCount)
                    {
                        continue;
                    }
                    result.Insert(position, newItem);

                    if (result.Count > WithSamePrefixWordMaxCount)
                    {
                        result.RemoveAt(WithSamePrefixWordMaxCount);
                    }
                    continue;
                }

                GetWords(node, result, prefix + node.Element.CharKey);
            }
        }
Example #2
0
 public int BinarySearchTest(IReadOnlyList <KeyValuePair <string, int> > wordsWithFrequency,
                             KeyValuePair <string, int> item)
 {
     return(BinarySearch.BinarySearchForStringWithFrequency(wordsWithFrequency, item));
 }