示例#1
0
 public AsciiFileReader(CommandInterpreter interpreter)
 {
     using (var sr = new StreamReader(interpreter.Path, interpreter.Encoding)) {
     Data = sr.ReadToEnd();
       }
 }
示例#2
0
        public void TestBinaryFiles()
        {
            var gen = new Random();
              var files = Directory.EnumerateFiles(DirectoryString + @"\GenFiles\", "B_*");
              foreach (var file in files) {
            var ob = new StatObj { FileName = file };
            var commandLineInterpreter = new CommandInterpreter() { Encoding = Encoding.UTF8, Path = ob.FileName };
            var fileReader = new AsciiFileReader(commandLineInterpreter);
            var sa = new SuffixArrayAsc(fileReader.Data);
            var bwt = new BurrowsWheelerTransformAsc(sa);

            for (var i = 1; i < Math.Min(20, ob.FileSize / 2); i++) {
              ob.PatternSize = i;
              commandLineInterpreter.QueryString = fileReader.Data.Substring(
              (int)(
                  (ob.FileSize - ob.PatternSize) * gen.NextDouble()
                  ), ob.PatternSize
              );
              ob.StartTimeTicks = (ulong)DateTime.Now.Ticks;
              /* try
               {*/
              ob.Results = bwt.CountOccurrences(commandLineInterpreter.QueryString);
              /*}
              catch
              {
              }*/
              ob.EndTimeTicks = (ulong)DateTime.Now.Ticks;
              Console.WriteLine("BWT,{0},{1},{2},{3},{4},{5}", ob.RuntimeTicks, ob.PatternSize, ob.FileSize, ob.AlphabetSize, ob.Results, Encoding.UTF8);
              ob.StartTimeTicks = (ulong)DateTime.Now.Ticks; /*try
                    {*/
              ob.Results = BruteForce.Run(fileReader.Data, commandLineInterpreter.QueryString);
              /*}
              catch
              {
              }*/
              ob.EndTimeTicks = (ulong)DateTime.Now.Ticks;
              Console.WriteLine("BruteForce,{0},{1},{2},{3},{4},{5}", ob.RuntimeTicks, ob.PatternSize, ob.FileSize, ob.AlphabetSize, ob.Results, Encoding.UTF8);
            }
              }
        }
示例#3
0
        public void TestAsciiFiles()
        {
            var gen = new Random();
              var files = Directory.EnumerateFiles(DirectoryString + @"\GenFiles\", "*").Where(u => !u.Contains(@"GenFiles\B_"));
              foreach (var file in files) {
            var ob = new StatObj { FileName = file };
            var commandLineInterpreter = new CommandInterpreter() { Encoding = Encoding.ASCII, Path = ob.FileName };
            var fileReader = new AsciiFileReader(commandLineInterpreter);
            var sa = new SuffixArrayAsc(fileReader.Data);
            var bwt = new BurrowsWheelerTransformAsc(sa);
            int bwtWins = 0;
            int bfWins = 0;
            for (var i = 1; i < Math.Min(2, ob.FileSize / 2); i++) {
              ob.PatternSize = i;
              commandLineInterpreter.QueryString = fileReader.Data.Substring(
              (int)(
                  (ob.FileSize - ob.PatternSize) * gen.NextDouble()
                  ), ob.PatternSize
              );
              Console.WriteLine(commandLineInterpreter.QueryString);

              // Settings and timers
              //===============================================================
              int times = 1000;
              Stopwatch sw;
              //===============================================================

              // BWT
              //===============================================================
              StatObj bwtStat = ob;
              bwtStat.EndTimeTicks = 0;
              bwtStat.Results = 0;
              bwtStat.RuntimeTicks = 0;
              bwtStat.StartTimeTicks = 0;

              sw = Stopwatch.StartNew();
              for (int t = 0; t < times; t++) {
            bwtStat.Results = bwt.CountOccurrences(commandLineInterpreter.QueryString);
              }
              sw.Stop();

              bwtStat.RuntimeTicks = sw.ElapsedMilliseconds; //(ulong)sw.ElapsedTicks;
              //===============================================================

              // BF
              //===============================================================
              StatObj bfStat = ob;
              bfStat.EndTimeTicks = 0;
              bfStat.Results = 0;
              bfStat.RuntimeTicks = 0;
              bfStat.StartTimeTicks = 0;

              sw = Stopwatch.StartNew();
              for (int t = 0; t < times; t++) {
            bfStat.Results = BruteForce.Run(fileReader.Data, commandLineInterpreter.QueryString);
              }
              sw.Stop();

              bfStat.RuntimeTicks = sw.ElapsedMilliseconds; //(ulong)sw.ElapsedTicks;
              //===============================================================

              // Print Results
              //===============================================================
              //Console.WriteLine("BWT,{0},{1},{2},{3},{4},{5}", ob.RuntimeTicks, ob.PatternSize, ob.FileSize, ob.AlphabetSize, ob.Results, Encoding.ASCII);
              //Console.WriteLine("BruteForce,{0},{1},{2},{3},{4},{5}", ob.RuntimeTicks, ob.PatternSize, ob.FileSize, ob.AlphabetSize, ob.Results, Encoding.ASCII);

              //Console.WriteLine("BWT: {0}", bwtStat.RuntimeTicks);
              //Console.WriteLine(" BF: {0}", bfStat.RuntimeTicks);

              if (bwtStat.Results != bfStat.Results) {
            Console.WriteLine("\nBWT FAILED US!\n");
              }

              if (bfStat.RuntimeTicks >= bwtStat.RuntimeTicks)
            bwtWins++;
              else
            bfWins++;
              //===============================================================
            }
            Console.WriteLine(ob.FileName + "\nBWT Wins: " + bwtWins + "\nBF Wins: " + bfWins + "\n");
              }
        }
示例#4
0
 public BinaryFileReader(CommandInterpreter interpreter)
 {
     byte[] fileBytes = File.ReadAllBytes(interpreter.Path);
       Data = new BitArray(fileBytes);
 }