Exemplo n.º 1
0
        public Dictionary <string, int> FindMatches(string prefix)
        {
            HeapTrieNode lastNode = root;

            for (int i = 0; i < prefix.Length; i++)
            {
                lastNode = lastNode.GetChild(prefix[i]);
                if (lastNode == null)
                {
                    return(new Dictionary <string, int>());
                }
            }
            return(lastNode.GetWords());
        }
Exemplo n.º 2
0
        public Dictionary <string, int> GetWords()
        {
            Dictionary <string, int> dictionary = new Dictionary <string, int>();

            if (IsEnd)
            {
                dictionary.Add(ToWord(), SearchCount);
            }
            if (Children.Any())
            {
                for (int i = 0; i < Children.Count; i++)
                {
                    HeapTrieNode currentChild = Children.ElementAt(i);
                    if (currentChild != null)
                    {
                        foreach (var item in currentChild.GetWords())
                        {
                            dictionary.Add(item.Key, item.Value);
                        }
                    }
                }
            }
            return(dictionary);
        }