本文整理汇总了C#中Trie.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# Trie.GetEnumerator方法的具体用法?C# Trie.GetEnumerator怎么用?C# Trie.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Trie
的用法示例。
在下文中一共展示了Trie.GetEnumerator方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoTest
//.........这里部分代码省略.........
// Count of words = 9
Debug.Assert(trie.Count == 9);
//
// ASSERT THE WORDS IN TRIE.
// Search for a word that doesn't exist
Debug.Assert(false == trie.ContainsWord(prefix_howTo));
// Search for prefix
Debug.Assert(true == trie.ContainsPrefix(prefix_howTo));
// Search for a prefix using a word
Debug.Assert(true == trie.ContainsPrefix(word_howToSand));
// Get all words that start with the how-to prefix
var someHowToWords = trie.SearchByPrefix(prefix_howTo).ToList();
Debug.Assert(someHowToWords.Count == listOfHow.Count);
// Assert there are only two words under the prefix "acti" -> active, & acting
var someActiWords = trie.SearchByPrefix("acti").ToList<string>();
Debug.Assert(someActiWords.Count == 2);
Debug.Assert(someActiWords.Contains(word_acting));
Debug.Assert(someActiWords.Contains(word_active));
// Assert that "acto" is not a word
Debug.Assert(trie.ContainsWord("acto") == false);
// Check the existance of other words
Debug.Assert(trie.ContainsWord(word_actress) == true);
Debug.Assert(trie.ContainsWord(word_howToProp) == true);
//
// TEST DELETING SOMETHINGS
// Removing a prefix should fail
var removing_acto_fails = false;
try
{
// try removing a non-terminal word
trie.Remove("acto");
removing_acto_fails = false;
}
catch
{
// if exception occured then code works, word doesn't exist.
removing_acto_fails = true;
}
Debug.Assert(removing_acto_fails == true);
Debug.Assert(trie.Count == 9);
// Removing a word should work
var removing_acting_passes = false;
try
{
// try removing a non-terminal word
trie.Remove(word_acting);
removing_acting_passes = true;
}
catch
{
// if exception occured then code DOESN'T work, word does exist.
removing_acting_passes = false;
}
Debug.Assert(removing_acting_passes == true);
Debug.Assert(trie.Count == 8);
someActiWords = trie.SearchByPrefix("acti").ToList<string>();
Debug.Assert(someActiWords.Count == 1);
Debug.Assert(someActiWords.Contains(word_active));
//
// TEST ENUMERATOR
var enumerator = trie.GetEnumerator();
var allWords = new List<string>();
while (enumerator.MoveNext())
allWords.Add(enumerator.Current);
// Assert size
Debug.Assert(allWords.Count == trie.Count);
// Assert each element
foreach (var word in allWords)
Debug.Assert(listOfActWords.Contains(word) || listOfHow.Contains(word));
Console.WriteLine("Testing is finished.");
Console.ReadLine();
}