Crate bit_parallel_search

Crate bit_parallel_search 

Source
Expand description

Blazing fast string search using bit-parallel algorithms.

§When to Use This

PERFECT FOR:

  • Patterns ≤ 64 bytes (processor word size)
  • High-frequency searches (millions per second)
  • Embedded systems (no_std support)
  • HTTP header parsing, log analysis, protocol parsing

DON’T USE FOR:

  • Patterns > 64 bytes (falls back to naive, becomes slower)
  • Complex patterns (use regex instead)
  • Unicode-aware search (this is byte-level only)
  • One-off searches (setup overhead not worth it)

§Performance (Brutal Honesty)

Pattern Lengthvs Naivevs memchrvs Regex
1-8 bytes5-8x faster0.8x10x faster
9-16 bytes3-5x fasterN/A8x faster
17-32 bytes2-3x fasterN/A5x faster
33-64 bytes1.5-2x fasterN/A3x faster
65+ bytes0.5x SLOWERN/A0.3x SLOWER

§Example

use bit_parallel_search::BitParallelSearcher;

let text = b"The quick brown fox jumps over the lazy dog";
let pattern = b"fox";

// Single search
let searcher = BitParallelSearcher::new(pattern);
assert_eq!(searcher.find_in(text), Some(16));

// Multiple searches (amortizes setup cost)
for text in large_text_corpus {
    if let Some(pos) = searcher.find_in(text) {
        // Found at position pos
    }
}

Structs§

BitParallelSearcher
Pre-computed searcher for a specific pattern.
FindAllIterstd
Iterator for finding all matches.

Constants§

MAX_PATTERN_LEN
Maximum pattern length for bit-parallel algorithm. Beyond this, we fall back to naive search (and become slower).

Functions§

find
Convenience function for one-off searches.