예제 #1
0
        public List <string> AutoComplete(TrieDescription trie, string pattern)
        {
            // Because the two first characters are the Id of the TrieRoot object
            pattern = pattern.ToLower().Substring(2);

            TrieDescription start = trie;

            for (int i = 0; i < pattern.Length; ++i)
            {
                int ind = TrieConstants.GetCharIndex(pattern[i]);
                if (trie.Children[ind] == null)
                {
                    return(new List <string>());
                }
                if (i == pattern.Length - 1)
                {
                    start = trie.Children[ind];
                    break;
                }
                trie = trie.Children[ind];
            }

            var words = ListWords(start);

            for (var i = 0; i < words.Count; ++i)
            {
                words[i] = Id + pattern + words[i];
            }

            return(words);
        }
예제 #2
0
        public List <string> ListWords(TrieDescription trie)
        {
            var    words = new List <string>();
            string cur   = "";

            ListWordsRec(trie, ref words, cur);

            return(words);
        }
예제 #3
0
        private void ListWordsRec(TrieDescription trie, ref List <string> words, string cur)
        {
            /// Limit number of autocompleted elements
            if (trie == null || words.Count > 10)
            {
                return;
            }
            else if (trie.IsWord)
            {
                words.Add(cur);
            }

            for (int i = 0; i < TrieConstants.NbCharSupported; ++i)
            {
                if (trie.Children[i] != null)
                {
                    string n = cur + trie.Children[i].Key;
                    ListWordsRec(trie.Children[i], ref words, n);
                }
            }
        }