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


C# Trie.Insert方法代码示例

本文整理汇总了C#中Trie.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# Trie.Insert方法的具体用法?C# Trie.Insert怎么用?C# Trie.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Trie的用法示例。


在下文中一共展示了Trie.Insert方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TrieTests_Contains2

        public void TrieTests_Contains2()
        {
            Trie<int> trie = new Trie<int>();

            int[] array = new int[] { 1, 2, 3 };

            trie.Insert(array);
            trie.Insert(new int[] { });

            Assert.IsTrue(trie.Contains(new int[] { }));
            Assert.IsTrue(trie.Contains(array));
            Assert.IsFalse(trie.Contains(new int[] { 1, 2 }));
        }
开发者ID:ZuTa,项目名称:Algorithms,代码行数:13,代码来源:TrieTests.cs

示例2: Main

    static void Main()
    {
        Trie trie = new Trie();
        trie.Insert("Svetlin");
        trie.Insert("Nakov");
        trie.Insert("Niki");

        Console.WriteLine("Searching for svetlin -> {0}", trie.Search("svetlin"));
        Console.WriteLine("Searching for nakov -> {0}", trie.Search("nakov"));
        Console.WriteLine("Searching for Svetlin -> {0}", trie.Search("Svetlin"));
        Console.WriteLine("Searching for Nakov -> {0}", trie.Search("Nakov"));
        Console.WriteLine("Searching for Nik -> {0}", trie.Search("Nik"));
        Console.WriteLine("Searching for iki-> {0}", trie.Search("iki"));
        Console.WriteLine("Searching for Niki -> {0}", trie.Search("Niki"));
    }
开发者ID:bahtev,项目名称:TelerikAcademy,代码行数:15,代码来源:Program.cs

示例3: TrieTests_EnumerateInOrder2

        public void TrieTests_EnumerateInOrder2()
        {
            Trie<char> trie = new Trie<char>();

            List<string> items = new List<string>();

            Random r = new Random();
            for (int i = 0; i < 100000; i++)
            {
                char[] word = new char[r.Next(10) + 1];

                for (int j = 0; j < word.Length; j++)
                {
                    word[j] = (char)(97 + r.Next(26));
                }

                string sword = new string(word);

                items.Add(sword);

                trie.Insert(sword);
            }

            items.Sort();

            var actualOrder = trie.EnumerateInOrder().Select(sequence => new string(sequence.ToArray())).ToList();

            Assert.IsTrue(items.Except(actualOrder).Count() == 0);
            Assert.IsTrue(actualOrder.Except(items).Count() == 0);
        }
开发者ID:ZuTa,项目名称:Algorithms,代码行数:30,代码来源:TrieTests.cs

示例4: AddWords

 public void AddWords()
 {
     words = new Trie();
     CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
     CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
     CloudBlobContainer container = blobClient.GetContainerReference("http://hudpoi459storage.blob.core.windows.net/hudson/");
     CloudBlockBlob blockBlob = container.GetBlockBlobReference("wikipedia.txt");
     try
     {
         using (var stream = blockBlob.OpenRead())
         {
             using (StreamReader sr = new StreamReader(stream))
             {
                 string line;
                 while ((line = sr.ReadLine()) != null)
                 {
                     words.Insert(line);
                 }
             }
         }
     }
     catch (OutOfMemoryException)
     {
         GC.Collect();
     }
 }
开发者ID:hudpoi459,项目名称:Info344,代码行数:26,代码来源:WebService.cs

示例5: TrieTests_Contains

        public void TrieTests_Contains()
        {
            Trie<char> trie = new Trie<char>();

            trie.Insert("Hello");

            Assert.IsTrue(trie.Contains("Hello"));
            Assert.IsFalse(trie.Contains("Hell"));
            Assert.IsFalse(trie.Contains("Hellop"));
        }
开发者ID:ZuTa,项目名称:Algorithms,代码行数:10,代码来源:TrieTests.cs

示例6: AddWordsUsingTrie

        private static void AddWordsUsingTrie(Trie trie, List<string> wordsFromText, Stopwatch sw)
        {
            sw.Restart();
            foreach (string word in wordsFromText)
            {
                trie.Insert(word);
            }
            sw.Stop();

            Console.WriteLine("{0} words added  to Trie in: {1} time", wordsFromText.Count, sw.Elapsed);
        }
开发者ID:Cecosam,项目名称:Csharp-Projects,代码行数:11,代码来源:TrieDemo.cs

示例7: TestTrieGreedyStarFunctionality

        public void TestTrieGreedyStarFunctionality()
        {
            var endPointDescriptor = new TestEndPointDescriptor {
                Name = "foo",
            };

            var firstTrie = new Trie();
            firstTrie.Insert("api-docs/{path*}", endPointDescriptor);

            var uri = new Uri("http://localhost:8081/api-docs/content/stories");

            Regex rgx;

            var endPoint = firstTrie.ResolveRequest(uri, out rgx);
            Assert.AreEqual("foo", endPoint.Name);
        }
开发者ID:scoutmedia,项目名称:Sid,代码行数:16,代码来源:TrieTests.cs

示例8: TrieTests_EnumerateInOrder

        public void TrieTests_EnumerateInOrder()
        {
            Trie<char> trie = new Trie<char>();

            List<string> items = new List<string>() { "abcd", "abc" };
            foreach (string item in items)
            {
                trie.Insert(item);
            }

            items.Sort();

            var actualOrder = trie.EnumerateInOrder().Select(sequence => new string(sequence.ToArray())).ToList();

            Assert.IsTrue(items.Except(actualOrder).Count() == 0);
            Assert.IsTrue(actualOrder.Except(items).Count() == 0);
        }
开发者ID:ZuTa,项目名称:Algorithms,代码行数:17,代码来源:TrieTests.cs

示例9: TestMethod

 public void TestMethod(int opCount, int maxWordLength)
 {
     var trie = new Trie();
     var list = new List<string>();
     while (opCount-- > 0)
     {
         var word = GenerateString(1, maxWordLength, 'a', 'z');
         switch (Random.Next(3))
         {
             case 0:
                 trie.Insert(word);
                 list.Add(word);
                 break;
             case 1:
                 Assert.AreEqual(list.Contains(word), trie.Search(word));
                 break;
             case 2:
                 Assert.AreEqual(list.Any(w => w.StartsWith(word)), trie.StartsWith(word));
                 break;
         }
     }
 }
开发者ID:alexguo88,项目名称:LeetCode,代码行数:22,代码来源:208.ImplementTrie.Test.cs

示例10: TestTrieMerge

        public void TestTrieMerge()
        {
            var endPointDescriptor = new TestEndPointDescriptor {
                Name = "foo",
            };

            var firstTrie = new Trie();
            firstTrie.Insert("firstSegment/secondSegment", null);
            var secondTrie = new Trie();

            var path = "firstSegment/anotherSegment";

            secondTrie.Insert(path,  endPointDescriptor);

            firstTrie.Merge(secondTrie, path);

            var uri = new Uri("http://localhost:8081/firstSegment/anotherSegment");

            Regex rgx;

            var endPoint = firstTrie.ResolveRequest(uri, out rgx);
            Assert.AreEqual("foo", endPoint.Name);
        }
开发者ID:scoutmedia,项目名称:Sid,代码行数:23,代码来源:TrieTests.cs

示例11: TestStaticEndPointAfterTokenizedEndPoint

        public void TestStaticEndPointAfterTokenizedEndPoint()
        {
            var endPointDescriptor = new TestEndPointDescriptor {
                Name = "foo",
            };

            var firstTrie = new Trie();
            firstTrie.Insert("content/media/{id}", endPointDescriptor);
            var secondTrie = new Trie();

            var path = "content/media/search";

            secondTrie.Insert(path,  null);

            firstTrie.Merge(secondTrie, path);

            var uri = new Uri("http://localhost:8081/content/media/12345");

            Regex rgx;

            var endPoint = firstTrie.ResolveRequest(uri, out rgx);
            Assert.AreEqual("foo", endPoint.Name);
        }
开发者ID:scoutmedia,项目名称:Sid,代码行数:23,代码来源:TrieTests.cs

示例12: TestTrieMergeSegAfterToken

        public void TestTrieMergeSegAfterToken()
        {
            var endPointDescriptor1 = new TestEndPointDescriptor {
                Name = "foo",
            };
            var endPointDescriptor2 = new TestEndPointDescriptor {
                Name = "bar",
            };

            Regex rgx;
            var path = "content/sites/{siteId}/settings";
            var uri1 = new Uri("http://localhost:8081/content/sites/2343");
            var uri2 = new Uri("http://localhost:8081/content/sites/2343/settings");

            var insertTrie = new Trie();
            insertTrie.Insert("content/sites/{id}", endPointDescriptor1);
            insertTrie.Insert(path, endPointDescriptor2);

            var endPointPre = insertTrie.ResolveRequest(uri1, out rgx);
            Assert.AreEqual("foo", endPointPre.Name);

            endPointPre = insertTrie.ResolveRequest(uri2, out rgx);
            Assert.AreEqual("bar", endPointPre.Name);

            var mergeTrie = new Trie();
            mergeTrie.Insert("content/sites/{id}", endPointDescriptor1);

            var singleEndPointTrie = new Trie();
            singleEndPointTrie.Insert(path,  endPointDescriptor2);

            mergeTrie.Merge(singleEndPointTrie, path);

            var endPoint = mergeTrie.ResolveRequest(uri1, out rgx);
            Assert.AreEqual("foo", endPoint.Name);

            endPoint = mergeTrie.ResolveRequest(uri2, out rgx);
            Assert.AreEqual("bar", endPoint.Name);
        }
开发者ID:scoutmedia,项目名称:Sid,代码行数:38,代码来源:TrieTests.cs

示例13: TestTrieMergeSecondWithNoToken

        public void TestTrieMergeSecondWithNoToken()
        {
            var endPointDescriptor = new TestEndPointDescriptor {
                Name = "foo",
            };

            Regex rgx;
            var path = "content/sites";
            var uri = new Uri("http://localhost:8081/content/sites");

            var firstTrie = new Trie();
            firstTrie.Insert("content/sites/{siteId}", null);
            var secondTrie = new Trie();
            secondTrie.Insert(path,  endPointDescriptor);
            firstTrie.Merge(secondTrie, path);

            var endPoint = firstTrie.ResolveRequest(uri, out rgx);
            Assert.AreEqual("foo", endPoint.Name);
        }
开发者ID:scoutmedia,项目名称:Sid,代码行数:19,代码来源:TrieTests.cs


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