コード例 #1
0
 public void RemovePrefix01()
 {
     trie.RemovePrefix("1");
     Assert.AreEqual(8, trie.GetWords().Count);
     trie.RemovePrefix("th");
     Assert.AreEqual(6, trie.GetWords().Count);
     trie.RemovePrefix("x");
     Assert.AreEqual(6, trie.GetWords().Count);
     trie.RemovePrefix("");
     Assert.AreEqual(0, trie.GetWords().Count);
 }
コード例 #2
0
 public void TrieRemoveByPrefixBenchmark()
 {
     for (int i = 0; i < _words.Length; i++)
     {
         _trie.RemovePrefix(_words[i].DeleteLastCharacter());
     }
     Assert.AreEqual(0, _trie.Count);
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: GaikwadPratik/CS570AlgoDS
        private static void TestTrie()
        {
            ITrie trie  = BuildTestTrie();
            var   words = trie.GetAllWords();

            Console.WriteLine($"Total word count in trie: {words.Count}");
            words = trie.GetWordsByPrefix("");
            Console.WriteLine($"Total words with empty prefix: {words.Count}");
            words = trie.GetWordsByPrefix("th");
            Console.WriteLine($"Total words with th prefix: {words.Count}");
            words = trie.GetWordsByPrefix("TH");
            Console.WriteLine($"Total words with TH prefix: {words.Count}");
            words = trie.GetWordsByPrefix("z");
            Console.WriteLine($"Total words with z prefix: {words.Count}");
            words = trie.GetWordsByPrefix("Z");
            Console.WriteLine($"Total words with Z prefix: {words.Count}");
            words = trie.GetWordsByPrefix("1");
            Console.WriteLine($"Total words with 1 prefix: {words.Count}");
            bool hasWord = trie.ContainsWord("test");

            Console.WriteLine($"Word 'test' found: {hasWord}");
            hasWord = trie.ContainsWord("TEST");
            Console.WriteLine($"Word 'TEST' found: {hasWord}");
            hasWord = trie.ContainsWord("zz");
            Console.WriteLine($"Word 'zz' found: {hasWord}");
            hasWord = trie.ContainsWord("ZZ");
            Console.WriteLine($"Word 'ZZ' found: {hasWord}");
            hasWord = trie.ContainsWord("Microsoft");
            Console.WriteLine($"Word 'Microsoft' found: {hasWord}");

            trie  = BuildTestTrie();
            words = trie.GetAllWords();
            Console.WriteLine($"Total word count in trie: {words.Count}");
            trie.RemoveWord("this");
            words = trie.GetAllWords();
            Console.WriteLine($"Total word count in trie: {words.Count}");
            trie.RemoveWord("the");
            words = trie.GetAllWords();
            Console.WriteLine($"Total word count in trie: {words.Count}");
            trie.RemoveWord("te");
            words = trie.GetAllWords();
            Console.WriteLine($"Total word count in trie: {words.Count}");
            trie.RemoveWord("test");
            words = trie.GetAllWords();
            Console.WriteLine($"Total word count in trie: {words.Count}");
            trie.RemoveWord("word not present");
            words = trie.GetAllWords();
            Console.WriteLine($"Total word count in trie: {words.Count}");
            trie.RemoveWord("123");
            foreach (var word in trie.GetAllWords())
            {
                trie.RemoveWord(word);
            }
            words = trie.GetAllWords();
            Console.WriteLine($"Total word count in trie: {words.Count}");

            trie = BuildTestTrie();
            trie.RemovePrefix("1");
            words = trie.GetAllWords();
            Console.WriteLine($"Total word count in trie: {words.Count}");
            trie.RemovePrefix("th");
            words = trie.GetAllWords();
            Console.WriteLine($"Total word count in trie: {words.Count}");
            trie.RemovePrefix("x");
            words = trie.GetAllWords();
            Console.WriteLine($"Total word count in trie: {words.Count}");
            trie.RemovePrefix("");
            words = trie.GetAllWords();
            Console.WriteLine($"Total word count in trie: {words.Count}");
        }