Example #1
0
        static void Main(string[] args)
        {
            const int textVLen = 100;
              const int patternVLen = 2;

              var encoder = new ByteStringEncoder();
              var operationTimeTester = new OperationTimeTester();

              var text = GetByte2DArray(@"..\doc\Text2D.t", textVLen);
              var pattern = GetByte2DArray(@"..\doc\Pattern2D.t", patternVLen);
              var patternString = encoder.GetStringTo2DArray(pattern);
              var patternSize = string.Format("{0}x{1}", pattern.GetLength(0), pattern.GetLength(1));
              var textSize = string.Format("{0}x{1}", text.GetLength(0), text.GetLength(1));

              var brute = new Brute2DPatternSearcher();
              var result = operationTimeTester.Test(brute.Search, pattern, text);
              Show("Text", textSize, "Brute", patternString, patternSize, result);

              var rabinkarp2DModulo13 = new RabinKarp2DPatternSearcher(new HashingService(256, 13));
              result = operationTimeTester.Test(rabinkarp2DModulo13.Search, pattern, text);
              Show("Text", textSize, "Rabin-Karp 2D with hashing modulo 13", patternString, patternSize, result);

              var rabinkarp2DModulo101 = new RabinKarp2DPatternSearcher(new HashingService(256, 101));
              result = operationTimeTester.Test(rabinkarp2DModulo101.Search, pattern, text);
              Show("Text", textSize, "Rabin-Karp 2D with hashing modulo 101", patternString, patternSize, result);

              var rabinkarp2DModulo2147483647 = new RabinKarp2DPatternSearcher(new HashingService(256, 2147483647));
              result = operationTimeTester.Test(rabinkarp2DModulo2147483647.Search, pattern, text);
              Show("Text", textSize, "Rabin-Karp 2D with hashing modulo 2147483647", patternString, patternSize, result);
        }
Example #2
0
        static void Main(string[] args)
        {
            var encoder = new ByteStringEncoder();
              var hashingArray = new HashingArray(new HashingService(256, 100000003), 100000003);

              FileStream stream = File.OpenRead(@"..\doc\pan_wolodyjowski_line.t");
              int myByte;
              string word = "";
              while ((myByte = stream.ReadByte()) != -1)
              {
            var inChar = encoder.GetString((byte)myByte);
            if (inChar != " " && inChar != "\n" && inChar != "\r")
            {
              word += inChar;
            }
            else
            {
              hashingArray.Add(word);
              word = "";
            }
              }

              var sb = new StringBuilder();
              using (var file = System.IO.File.AppendText(@"..\doc\words_count.t"))
              {
            foreach (var wordList in hashingArray)
            {
              foreach (var w in wordList)
              {
            sb.AppendLine(string.Format("Word: {0}, count: {1}",
            w.Value,
            w.Count));
            file.Write(sb.ToString());
            sb.Clear();
              }
            }
              }
        }
Example #3
0
        static void Main(string[] args)
        {
            var encoder = new ByteStringEncoder();
              var operationTimeTester = new OperationTimeTester();

              var text = File.ReadAllBytes(@"..\doc\pan_wolodyjowski_line_kopia.t");
              var pattern = File.ReadAllBytes(@"..\doc\Pattern_kopia.t");
              var patternString = encoder.GetString(pattern);
              var patternSize = pattern.Length;
              var textSize = text.Length;

              var brute = new BrutePatternSearcher();
              var result = operationTimeTester.Test(brute.Search, pattern, text);
              Show("Pan Wołodyjowski", textSize, "Brute", patternString, patternSize, result);

              Pause();

              var rabinkarpModulo13 = new RabinKarpPatternSearcher(new HashingService(256, 13));
              result = operationTimeTester.Test(rabinkarpModulo13.Search, pattern, text);
              Show("Pan Wołodyjowski", textSize, "Rabin-Karp with hashing modulo 13", patternString, patternSize, result);

              Pause();

              var rabinkarpModulo101 = new RabinKarpPatternSearcher(new HashingService(256, 101));
              result = operationTimeTester.Test(rabinkarpModulo101.Search, pattern, text);
              Show("Pan Wołodyjowski", textSize, "Rabin-Karp with hashing modulo 101", patternString, patternSize, result);

              Pause();

              var rabinkarpModulo2147483647 = new RabinKarpPatternSearcher(new HashingService(256, 2147483647));
              result = operationTimeTester.Test(rabinkarpModulo2147483647.Search, pattern, text);
              Show("Pan Wołodyjowski", textSize, "Rabin-Karp with hashing modulo 2147483647", patternString, patternSize, result);

              Pause();

              var suffixTree = new SuffixTree(text);
              System.Console.Out.WriteLine("Suffix tree building start...");
              var suffixTreeBuildingResult = operationTimeTester.Test(suffixTree.Initialize);
              System.Console.Out.WriteLine("Comparisons count: {0}", suffixTreeBuildingResult.OperationResult);
              System.Console.Out.WriteLine("Suffix tree building finished.");
              System.Console.Out.WriteLine("Elapsed: {0}", suffixTreeBuildingResult.Elapsed);
              System.Console.Out.WriteLine();

              Pause();

              result = operationTimeTester.Test(suffixTree.Find, pattern);
              Show("Pan Wołodyjowski", textSize, "Suffix Tree", patternString, patternSize, result);

              Pause();

              var suffixArray = new SuffixArray(text);
              System.Console.Out.WriteLine("Suffix array building start...");
              var suffixArrayBuildingResult = operationTimeTester.Test(suffixArray.Initialize);
              System.Console.Out.WriteLine("Comparisons count: {0}", suffixArrayBuildingResult.OperationResult);
              System.Console.Out.WriteLine("Suffix array building finished.");
              System.Console.Out.WriteLine("Elapsed: {0}", suffixArrayBuildingResult.Elapsed);
              System.Console.Out.WriteLine();

              Pause();

              result = operationTimeTester.Test(suffixArray.Find, pattern);
              Show("Pan Wołodyjowski", textSize, "Suffix Array", patternString, patternSize, result);

              Pause();
        }