当前位置: 首页>>代码示例>>C#>>正文


C# Trie.ContainsKey方法代码示例

本文整理汇总了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());
        }
开发者ID:MarinaGeorgieva,项目名称:TelerikAcademy,代码行数:27,代码来源:Startup.cs

示例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;
        }
开发者ID:Novkirishki,项目名称:Data-Structures-and-Algorithms,代码行数:32,代码来源:Startup.cs

示例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"));
        }
开发者ID:kpol,项目名称:trie,代码行数:18,代码来源:TrieTests.cs

示例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"));
        }
开发者ID:kpol,项目名称:trie,代码行数:23,代码来源:TrieTests.cs

示例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"));
        }
开发者ID:flashcurd,项目名称:Shared.Utilities,代码行数:17,代码来源:TrieTests.cs

示例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"));
        }
开发者ID:flashcurd,项目名称:Shared.Utilities,代码行数:15,代码来源:TrieTests.cs

示例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"));
        }
开发者ID:flashcurd,项目名称:Shared.Utilities,代码行数:16,代码来源:TrieTests.cs

示例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"));
        }
开发者ID:flashcurd,项目名称:Shared.Utilities,代码行数:8,代码来源:TrieTests.cs

示例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"));
        }
开发者ID:flashcurd,项目名称:Shared.Utilities,代码行数:8,代码来源:TrieTests.cs

示例10: ContainsKey_KeyIsNull_Throws

        public void ContainsKey_KeyIsNull_Throws()
        {
            Trie<string, char, int> trie = new Trie<string, char, int>();

            trie.ContainsKey(null);
        }
开发者ID:flashcurd,项目名称:Shared.Utilities,代码行数:6,代码来源:TrieTests.cs


注:本文中的Trie.ContainsKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。