Beispiel #1
0
        public void WasTyped(string word, int times)
        {
            if (String.IsNullOrEmpty(word))
            {
                this.popularity += times;
                return;
            }

            this.popularity += times;

            word = word.ToLower();

            var firstChar = word[0];
            var postfix   = word.Substring(1);

            if (Trie.IsLatinLetter(firstChar) == false)
            {
                return;
            }

            if (this.subTries[firstChar] == null)
            {
                this.subTries[firstChar] = new Trie();
            }

            this.subTries[firstChar].WasTyped(postfix, times);
        }
Beispiel #2
0
        public Trie GetSubTrie(char letter)
        {
            letter = Char.ToLower(letter);

            if (Trie.IsLatinLetter(letter) == false)
            {
                return(null);
            }

            return(this.subTries[letter] != null ? this.subTries[letter] : null);
        }
Beispiel #3
0
        public static bool IsValidWord(string word)
        {
            foreach (var letter in word)
            {
                if (Trie.IsLatinLetter(letter) == false)
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #4
0
 public bool ValidCharacter(char character)
 {
     return(Trie.IsLatinLetter(character) || Trie.IsWordSeparator(character));
 }