public AsciiCompiledTextSearchBndm64(string pattern, NativeMethods.SearchOptions searchOptions)
     : base(NativeMethods.SearchAlgorithmKind.kBndm64, pattern, searchOptions)
 {
     if (pattern.Length > 64)
     {
         throw new ArgumentException("Bndm64 algorithm is limited to patterns of 64 characters maximum.", "pattern");
     }
 }
 public AsciiStringSearchBndm32(string pattern, NativeMethods.SearchOptions searchOptions)
     : base(NativeMethods.SearchAlgorithmKind.kBndm32, pattern, searchOptions)
 {
     if (pattern.Length > 32)
     {
         throw new ArgumentException("Bndm32 algorithm is limited to patterns of 32 characters maximum.", "pattern");
     }
 }
Ejemplo n.º 3
0
        public unsafe void AsciiSearchForVariousPatternsWorks(
            long blockByteLength,
            string pattern,
            NativeMethods.SearchOptions searchOptions,
            int patternOccurrenceCount,
            int iterationCount)
        {
            Trace.WriteLine(
                string.Format(
                    "Searching {0} time(s) for pattern \"{1}\" with {2} occurrence(s) in a memory block of {3:n0} bytes.",
                    iterationCount, pattern, patternOccurrenceCount, blockByteLength));

            Assert.IsTrue(iterationCount >= 1);
            using (var textBlock = HeapAllocStatic.Alloc(blockByteLength)) {
                FillWithNonNulCharacters(textBlock);

                SetSearchMatches(textBlock, pattern, patternOccurrenceCount);

                using (var search = new AsciiStringSearchStrStr(pattern, searchOptions)) {
                    var sw         = Stopwatch.StartNew();
                    var matchCount = PerformSearch(textBlock, search, iterationCount);
                    sw.Stop();
                    Assert.AreEqual(patternOccurrenceCount, matchCount);
                    Trace.WriteLine(string.Format("  StrStr: Found {0:n0} occurrence(s) {1} times in {2}s ({3:n0} KB/s.)",
                                                  matchCount, iterationCount, sw.Elapsed.TotalSeconds,
                                                  ComputeThroughput(sw, blockByteLength, iterationCount)));
                }
                using (var search = new AsciiStringSearchBoyerMoore(pattern, searchOptions)) {
                    var sw         = Stopwatch.StartNew();
                    var matchCount = PerformSearch(textBlock, search, iterationCount);
                    sw.Stop();
                    Assert.AreEqual(patternOccurrenceCount, matchCount);
                    Trace.WriteLine(string.Format("  Boyer-Moore: Found {0:n0} occurrence(s) {1} times in {2} s ({3:n0} KB/s.)",
                                                  matchCount, iterationCount, sw.Elapsed.TotalSeconds,
                                                  ComputeThroughput(sw, blockByteLength, iterationCount)));
                }
                using (var search = new AsciiStringSearchBndm32(pattern, searchOptions)) {
                    var sw         = Stopwatch.StartNew();
                    var matchCount = PerformSearch(textBlock, search, iterationCount);
                    sw.Stop();
                    Assert.AreEqual(patternOccurrenceCount, matchCount);
                    Trace.WriteLine(string.Format("  BNDM-32: Found {0:n0} occurrence(s) {1} times in {2} s ({3:n0} KB/s.)",
                                                  matchCount, iterationCount, sw.Elapsed.TotalSeconds,
                                                  ComputeThroughput(sw, blockByteLength, iterationCount)));
                }
                using (var search = new AsciiStringSearchBndm64(pattern, searchOptions)) {
                    var sw         = Stopwatch.StartNew();
                    var matchCount = PerformSearch(textBlock, search, iterationCount);
                    sw.Stop();
                    Assert.AreEqual(patternOccurrenceCount, matchCount);
                    Trace.WriteLine(string.Format("  BNDM-64: Found {0:n0} occurrence(s) {1} times in {2} s ({3:n0} KB/s.)",
                                                  matchCount, iterationCount, sw.Elapsed.TotalSeconds,
                                                  ComputeThroughput(sw, blockByteLength, iterationCount)));
                }
            }
        }
Ejemplo n.º 4
0
 public static AsciiStringSearchAlgorithm CreateSearchAlgo(string pattern, NativeMethods.SearchOptions searchOptions)
 {
     if (pattern.Length <= 64)
     {
         return(new AsciiStringSearchBndm64(pattern, searchOptions));
     }
     else
     {
         return(new AsciiStringSearchBoyerMoore(pattern, searchOptions));
     }
 }
        public AsciiCompiledTextSearchNative(
            NativeMethods.SearchAlgorithmKind kind,
            string pattern,
            NativeMethods.SearchOptions searchOptions)
        {
            _patternHandle = new SafeHGlobalHandle(Marshal.StringToHGlobalAnsi(pattern));
            var patternLength = pattern.Length;

            _handle           = CreateSearchHandle(kind, _patternHandle, patternLength, searchOptions);
            _searchBufferSize = NativeMethods.AsciiSearchAlgorithm_GetSearchBufferSize(_handle);
        }
        private static unsafe SafeSearchHandle CreateSearchHandle(
            NativeMethods.SearchAlgorithmKind kind,
            SafeHGlobalHandle patternHandle,
            int patternLength,
            NativeMethods.SearchOptions searchOptions)
        {
            NativeMethods.SearchCreateResult createResult;
            var result = NativeMethods.AsciiSearchAlgorithm_Create(
                kind,
                patternHandle.Pointer,
                patternLength,
                searchOptions,
                out createResult);

            if (createResult.HResult < 0)
            {
                // The error is recoverable, since we are dealing with an invalid pattern
                // or something along the lines.
                var message = Marshal.PtrToStringAnsi(new IntPtr(createResult.ErrorMessage));
                throw new RecoverableErrorException(message);
            }

            return(result);
        }
 public AsciiCompiledTextSearchRe2(string pattern, NativeMethods.SearchOptions searchOptions)
     : base(NativeMethods.SearchAlgorithmKind.kRe2, pattern, searchOptions)
 {
 }
 public AsciiCompiledTextSearchBoyerMoore(string pattern, NativeMethods.SearchOptions searchOptions)
     : base(NativeMethods.SearchAlgorithmKind.kBoyerMoore, pattern, searchOptions)
 {
 }
Ejemplo n.º 9
0
 public static UTF16StringSearchAlgorithm CreateSearchAlgo(string pattern, NativeMethods.SearchOptions searchOptions)
 {
     return(new StrStrWStringSearchAlgorithm(pattern, searchOptions));
 }
 public Utf16CompiledTextSearchStdSearch(string pattern, NativeMethods.SearchOptions searchOptions) {
   _patternPtr = new SafeHGlobalHandle(Marshal.StringToHGlobalUni(pattern));
   _patternLength = pattern.Length;
   _searchOptions = searchOptions;
 }
Ejemplo n.º 11
0
 public StrStrWStringSearchAlgorithm(string pattern, NativeMethods.SearchOptions searchOptions)
 {
     _searchTextUniPtr = new SafeHGlobalHandle(Marshal.StringToHGlobalUni(pattern));
     _searchOptions    = searchOptions;
     _patternLength    = pattern.Length;
 }
Ejemplo n.º 12
0
 public Utf16CompiledTextSearchStdSearch(string pattern, NativeMethods.SearchOptions searchOptions)
 {
     _patternPtr    = new SafeHGlobalHandle(Marshal.StringToHGlobalUni(pattern));
     _patternLength = pattern.Length;
     _searchOptions = searchOptions;
 }
Ejemplo n.º 13
0
 public AsciiStringSearchNative(NativeMethods.SearchAlgorithmKind kind, string pattern, NativeMethods.SearchOptions searchOptions)
 {
     _patternHandle = new SafeHGlobalHandle(Marshal.StringToHGlobalAnsi(pattern));
     _handle        = NativeMethods.AsciiSearchAlgorithm_Create(kind, _patternHandle.Pointer, pattern.Length, searchOptions);
     _patternLength = pattern.Length;
 }
 public StrStrWStringSearchAlgorithm(string pattern, NativeMethods.SearchOptions searchOptions)
 {
     _searchTextUniPtr = new SafeHGlobalHandle(Marshal.StringToHGlobalUni(pattern));
       _searchOptions = searchOptions;
       _patternLength = pattern.Length;
 }
Ejemplo n.º 15
0
 public AsciiStringSearchStrStr(string pattern, NativeMethods.SearchOptions searchOptions)
     : base(NativeMethods.SearchAlgorithmKind.kStrStr, pattern, searchOptions)
 {
 }