Expand description
§Bit-Parallel String Search
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_stdsupport) - 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 Length | vs Naive | vs memchr | vs Regex |
|---|---|---|---|
| 1-8 bytes | 5-8x faster | 0.8x | 10x faster |
| 9-16 bytes | 3-5x faster | N/A | 8x faster |
| 17-32 bytes | 2-3x faster | N/A | 5x faster |
| 33-64 bytes | 1.5-2x faster | N/A | 3x faster |
| 65+ bytes | 0.5x SLOWER | N/A | 0.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§
- BitParallel
Searcher - Pre-computed searcher for a specific pattern.
- Find
AllIter std - 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.