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


C# Trie.HasPositionalSearch方法代码示例

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


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

示例1: Test

        public static void Test()
        {
            var testcase = StringSearchTestCase.New(50, 10, 100000);
            Stopwatch stopWatch = new Stopwatch();

            //searcher
            StringSearcher searcher = new StringSearcher();
            stopWatch.Start();
            testcase.TestDictionary.WithEach(x =>
            {
                searcher.Add(x, x);
            });
            stopWatch.Stop();
            Debug.WriteLine("searcher init elapsed ms {0}", stopWatch.ElapsedMilliseconds);

            stopWatch.Reset();
            stopWatch.Start();
            var searchermatches = searcher.FindMatches(testcase.TestSearchText);
            stopWatch.Stop();
            Debug.WriteLine("searcher elapsed ms {0}", stopWatch.ElapsedMilliseconds);
            Debug.WriteLine(
                string.Format("expected percent {0}.  found {1}", testcase.ExpectedPercentMatch, searchermatches.Count())
                );

            stopWatch.Reset();
            stopWatch.Start();
            //trie
            Trie trie = new Trie();
            testcase.TestDictionary.WithEach(x =>
            {
                trie.Add(x, x);
            });
            stopWatch.Stop();
            Debug.WriteLine("trie init elapsed ms {0}", stopWatch.ElapsedMilliseconds);

            stopWatch.Reset();
            stopWatch.Start();
            var matches = trie.FindMatches(testcase.TestSearchText);
            stopWatch.Stop();
            Debug.WriteLine("forwardonly elapsed ms {0}", stopWatch.ElapsedMilliseconds);
            Debug.WriteLine(
                string.Format("expected percent {0}.  found {1}", testcase.ExpectedPercentMatch, matches.Count())
                );

            stopWatch.Reset();
            stopWatch.Start();
            var matches1b = TrieLogic.FindMatchesUsingForwardOnlyCursor2(trie, testcase.TestSearchText);
            stopWatch.Stop();
            Debug.WriteLine("forwardonly2 elapsed ms {0}", stopWatch.ElapsedMilliseconds);
            Debug.WriteLine(
                string.Format("expected percent {0}.  found {1}", testcase.ExpectedPercentMatch, matches1b.Count())
                );

            stopWatch.Reset();
            stopWatch.Start();
            var matches2 = trie.HasPositionalSearch().FindMatches(testcase.TestSearchText);
            stopWatch.Stop();
            Debug.WriteLine("seekahead elapsed ms {0}", stopWatch.ElapsedMilliseconds);
            Debug.WriteLine(
                string.Format("expected percent {0}.  found {1}", testcase.ExpectedPercentMatch, matches2.Count())
                );

            stopWatch.Reset();
            stopWatch.Start();
            var matches3 = trie.HasPositionalSearch().NonOverlapping().FindMatches(testcase.TestSearchText);
            stopWatch.Stop();
            Debug.WriteLine("seekaheadnonoverlapped elapsed ms {0}", stopWatch.ElapsedMilliseconds);
            Debug.WriteLine(
                string.Format("expected percent {0}.  found {1}", testcase.ExpectedPercentMatch, matches3.Count())
                );

            stopWatch.Reset();
            stopWatch.Start();
            var matches4 = trie.HasPositionalSearch().Paralleling().FindMatches(testcase.TestSearchText);
            stopWatch.Stop();
            Debug.WriteLine("seekaheadparallel elapsed ms {0}", stopWatch.ElapsedMilliseconds);
            Debug.WriteLine(
                string.Format("expected percent {0}.  found {1}", testcase.ExpectedPercentMatch, matches4.Count())
                );

            //stopWatch.Reset();
            //stopWatch.Start();
            //InlineTrie inline_trie = new InlineTrie();
            //stopWatch.Start();
            //testcase.TestDictionary.WithEach(x =>
            //{
            //    inline_trie.Add(x, x);
            //});
            //stopWatch.Stop();
            //Debug.WriteLine("inline init elapsed ms {0}", stopWatch.ElapsedMilliseconds);
            //stopWatch.Reset();
            //stopWatch.Start();
            //var inline_matches = inline_trie.FindMatches(testcase.TestSearchText);
            //stopWatch.Stop();
            //Debug.WriteLine("inline elapsed ms {0}", stopWatch.ElapsedMilliseconds);
            //Debug.WriteLine(
            //    string.Format("expected percent {0}.  found {1}", testcase.ExpectedPercentMatch, inline_matches.Count)
            //    );

            ////trie
//.........这里部分代码省略.........
开发者ID:Piirtaa,项目名称:Decoratid,代码行数:101,代码来源:StringSearchTestUtil.cs


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