Example #1
0
        private static void SuffixArray__test_ThreadRoutine(SuffixArrayBase <tuple> sa, Barrier br)
        {
            var th = new Thread(_ /*state*/ =>
            {
                br.SignalAndWait();

                const int MAX = 51;

                var sb = new StringBuilder();
                for (var rnd = new Random(Thread.CurrentThread.ManagedThreadId); ; sb.Clear())
                {
                    var len = rnd.Next(1, 10);
                    for ( ; 0 <= len; len--)
                    {
                        sb.Append((char)rnd.Next('a', 'z' + 1));
                    }

                    var frs = sa.Find(sb.ToString());
                    var sum = frs.Take(MAX).Sum(fr => fr.GetSuffix().Length);
                    //foreach ( var fr in frs.Take( MAX ) )
                    //{
                    //    x += fr.GetSuffix().Length;
                    //}
                    Console.WriteLine(sum);
                }
            })
            {
                IsBackground = true
            };

            th.Start();
        }
Example #2
0
        private static void SuffixArray__test(SuffixArrayBase <tuple> sa)
        {
            Action <string> find = (suffix) =>
            {
                const int MAX       = 51;
                var       findCount = 0;
                var       frs       = sa.Find(suffix);
                foreach (var fr in frs)
                {
                    findCount++;
                    if (findCount < MAX)
                    {
                        if (findCount == 1)
                        {
                            Console.WriteLine($"\r\n suffix: '[{suffix}]'\r\n\t  =>");
                        }
                        Console.WriteLine($"\t '{fr.GetHighlightSuffix( "[", "]" ).ToLowerInvariant()}'");
                    }
                }
                //result
                if (0 < findCount)
                {
                    if (MAX < findCount)
                    {
                        Console.WriteLine($"\t ...else {(findCount - MAX + 1)}...");
                    }
                    Console.WriteLine($"\t  => ({findCount})");
                }
                else
                {
                    Console.WriteLine($"\r\n suffix: '{suffix}' => not found");
                }
            };

            find("ru");
            find("al");
            find("exe");
        }