本文整理汇总了C#中Trie.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# Trie.ContainsKey方法的具体用法?C# Trie.ContainsKey怎么用?C# Trie.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Trie
的用法示例。
在下文中一共展示了Trie.ContainsKey方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
Trie<int> trie = new Trie<int>();
using (StreamReader reader = new StreamReader("../../test.txt"))
{
while (!reader.EndOfStream)
{
string[] line = reader.ReadLine().Split(new char[] { ' ', '.', ',', '!', '?', ':', ';', '-' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
foreach (var word in line)
{
if (!trie.ContainsKey(word))
{
trie.Add(word, 1);
}
else
{
trie[word]++;
}
}
}
}
trie.Matcher.Next("eros");
Console.WriteLine(trie.Matcher.GetExactMatch());
}
示例2: ParseFile
private static Trie<int> ParseFile(string filename)
{
Trie<int> trie = new Trie<int>();
Console.WriteLine("Reading file and loading content in trie:");
using (StreamReader reader = new StreamReader(filename))
{
while (!reader.EndOfStream)
{
reader
.ReadLine()
.Split(' ', '.', ',', '?', '!', ':')
.ToList()
.ForEach(word =>
{
if (!trie.ContainsKey(word))
{
trie.Add(word, 1);
}
else
{
trie[word] += 1;
}
});
}
}
Console.WriteLine("File read and loaded into trie");
return trie;
}
示例3: ContainsKey
public void ContainsKey()
{
var trie = new Trie<bool>();
trie.Add("ABC", false);
trie.Add("AB", false);
trie.Add("ADE", false);
trie.Add("ABCDE", false);
Assert.IsTrue(trie.ContainsKey("ABC"));
Assert.IsTrue(trie.ContainsKey("AB"));
Assert.IsTrue(trie.ContainsKey("ADE"));
Assert.IsTrue(trie.ContainsKey("ABCDE"));
Assert.IsFalse(trie.ContainsKey("A"));
Assert.IsFalse(trie.ContainsKey("AC"));
Assert.IsFalse(trie.ContainsKey("ABCD"));
}
示例4: 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"));
}
示例5: Clear_NonEmptyCollection
public void Clear_NonEmptyCollection()
{
Trie<string, char, object> trie = new Trie<string, char, object>();
trie.Add("key1", 5);
trie.Add("key2", 5);
Assert.AreEqual(2, trie.Count);
Assert.IsTrue(trie.ContainsKey("key1"));
Assert.IsTrue(trie.ContainsKey("key2"));
trie.Clear();
Assert.AreEqual(0, trie.Count);
Assert.IsFalse(trie.ContainsKey("key1"));
Assert.IsFalse(trie.ContainsKey("key2"));
}
示例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: ContainsKey_KeyExists
public void ContainsKey_KeyExists()
{
Trie<string, char, int> trie = new Trie<string, char, int>();
trie.Add("key", 5);
Assert.IsTrue(trie.ContainsKey("key"));
}
示例9: ContainsKey_KeyDoesNotExist
public void ContainsKey_KeyDoesNotExist()
{
Trie<string, char, int> trie = new Trie<string, char, int>();
trie.Add("key", 5);
Assert.IsFalse(trie.ContainsKey("key2"));
}
示例10: ContainsKey_KeyIsNull_Throws
public void ContainsKey_KeyIsNull_Throws()
{
Trie<string, char, int> trie = new Trie<string, char, int>();
trie.ContainsKey(null);
}