本文整理汇总了C#中Trie.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# Trie.Remove方法的具体用法?C# Trie.Remove怎么用?C# Trie.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Trie
的用法示例。
在下文中一共展示了Trie.Remove方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveNullKey
public void RemoveNullKey()
{
var trie = new Trie<bool> { { "ABC", false } };
trie.Remove(null);
}
示例2: Remove
public void Remove()
{
const int InitialCount = 5;
var trie = new Trie<bool>
{
{ "ABC", false }, { "AB", false }, { "ADE", false }, { "ABCDE", false }, { "X", false }
};
Assert.IsFalse((trie as IDictionary<string, bool>).Remove(new KeyValuePair<string, bool>("XY", true)));
Assert.IsFalse((trie as IDictionary<string, bool>).Remove(new KeyValuePair<string, bool>("ABCD", true)));
Assert.IsFalse((trie as IDictionary<string, bool>).Remove(new KeyValuePair<string, bool>("ABCDE", true)));
Assert.AreEqual(InitialCount, trie.Count);
Assert.IsTrue((trie as IDictionary<string, bool>).Remove(new KeyValuePair<string, bool>("ABCDE", false)));
Assert.AreEqual(InitialCount - 1, trie.Count);
Assert.IsTrue(trie.Remove("X"));
Assert.AreEqual(InitialCount - 2, trie.Count);
Assert.IsTrue(trie.Remove("ABC"));
Assert.AreEqual(InitialCount - 3, trie.Count);
Assert.IsFalse(trie.ContainsKey("ABC"));
Assert.IsTrue(trie.ContainsKey("AB"));
Assert.IsTrue(trie.ContainsKey("ADE"));
}
示例3: RemoveNotExists
public void RemoveNotExists()
{
var trie = new Trie<bool> { { "ABC", false } };
Assert.IsFalse(trie.Remove("A"));
Assert.IsFalse(trie.Remove("X"));
}
示例4: DoTest
public static void DoTest()
{
var trie = new Trie();
// Insert some how to words
var prefix_howTo = "How to make";
var word_howToSand = prefix_howTo + " a sandwitch";
var word_howToRobot = prefix_howTo + " a robot";
var word_howToOmelet = prefix_howTo + " an omelet";
var word_howToProp = prefix_howTo + " a proposal";
var listOfHow = new List<string>() { word_howToSand, word_howToRobot, word_howToOmelet, word_howToProp };
trie.Add(word_howToOmelet);
trie.Add(word_howToSand);
trie.Add(word_howToRobot);
trie.Add(word_howToProp);
// Count of words = 4
Debug.Assert(trie.Count == 4);
// Insert some dictionary words
var prefix_act = "act";
var word_acts = prefix_act + "s";
var word_actor = prefix_act + "or";
var word_acting = prefix_act + "ing";
var word_actress = prefix_act + "ress";
var word_active = prefix_act + "ive";
var listOfActWords = new List<string>() { word_acts, word_actor, word_acting, word_actress, word_active };
trie.Add(word_actress);
trie.Add(word_active);
trie.Add(word_acting);
trie.Add(word_acts);
trie.Add(word_actor);
// 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;
//.........这里部分代码省略.........
示例5: Count_AfterRemoving
public void Count_AfterRemoving()
{
Trie<string, char, int> trie = new Trie<string, char, int>();
trie.Add("key1", 5);
trie.Add("key2", 6);
Assert.AreEqual(2, trie.Count);
trie.Remove("key1");
Assert.AreEqual(1, trie.Count);
trie.Remove("key2");
Assert.AreEqual(0, trie.Count);
}
示例6: Remove__KVPKeyDoesNotExist
public void Remove__KVPKeyDoesNotExist()
{
Trie<string, char, int> trie = new Trie<string, char, int>();
trie.Add("key1", 5);
Assert.AreEqual(1, trie.Count);
bool result = trie.Remove(new KeyValuePair<string, int>("key2", 1));
Assert.IsFalse(result);
Assert.AreEqual(1, trie.Count);
Assert.IsTrue(trie.ContainsKey("key1"));
Assert.IsFalse(trie.ContainsKey("key2"));
}
示例7: Remove_KVP_ItemIsRemoved
public void Remove_KVP_ItemIsRemoved()
{
Trie<string, char, int> trie = new Trie<string, char, int>();
trie.Add("key1", 5);
trie.Add("key2", 6);
Assert.AreEqual(2, trie.Count);
bool result = trie.Remove(trie.First(k => k.Key == "key1"));
Assert.IsTrue(result);
Assert.AreEqual(1, trie.Count);
Assert.IsFalse(trie.ContainsKey("key1"));
Assert.IsTrue(trie.ContainsKey("key2"));
}
示例8: Remove_KeyIsNull_Throws
public void Remove_KeyIsNull_Throws()
{
Trie<string, char, int> trie = new Trie<string, char, int>();
trie.Add("key", 5);
trie.Remove(null);
}