flash-fuzzy-core
High-performance fuzzy search engine core using Bitap algorithm with bloom filter pre-filtering.
Features
- Zero dependencies - Pure Rust implementation
no_stdcompatible - Works in embedded and WASM environments- Blazing fast - Bitap algorithm with bit-parallel operations
- Smart pre-filtering - 64-bit bloom filter rejects non-matches in O(1)
- Typo tolerant - Configurable edit distance (0-3 errors)
Quick Start
use ;
// Create a searcher for a pattern
let searcher = new;
// Check bloom filter first (O(1) rejection)
let text = b"Mechanical Keyboard Pro";
let text_bloom = from_text;
if text_bloom.might_contain
How It Works
1. Bloom Filter Pre-filtering
Before running expensive fuzzy matching, we check if the search pattern could possibly exist using a 64-bit bloom filter:
Text: "Wireless Laptop Pro" → bloom bits: 01001010...
Pattern: "laptop" → bloom bits: 00001010...
Check: (text_bloom & pattern_bloom) == pattern_bloom
If false → definitely no match, skip (80-95% of records rejected)
If true → might match, run Bitap
2. Bitap Algorithm
The Bitap (Shift-Or) algorithm uses bit-parallel operations for approximate string matching:
// Each error level tracks match state as a bitmask
R = exact matches
R = matches with 1 error
R = matches with 2 errors
...
API
BitapSearcher
BloomFilter
SearchMatch
Scoring
use compute_score;
// Score formula: base (1000 - errors*250) + position bonus (0-50)
let score = compute_score;
// Returns: 0-1000 (higher = better match)
| Errors | Base Score | + Start Bonus | Final |
|---|---|---|---|
| 0 | 1000 | +50 | 1000 (capped) |
| 1 | 750 | +25 (near start) | 775 |
| 2 | 500 | +0 | 500 |
| 3 | 250 | +0 | 250 |
no_std Usage
This crate is no_std by default:
[]
= "0.1"
Enable std feature for standard library support:
[]
= { = "0.1", = ["std"] }
Performance
- Pattern compilation: O(m) where m = pattern length
- Bloom check: O(1)
- Search: O(n * k) where n = text length, k = max errors
- Memory: ~1KB per searcher (256 u32 masks + state)
Typical benchmark: < 1ms to search 10,000 records.
License
MIT - see LICENSE
Part of Flash-Fuzzy
This is the core algorithm crate. For complete bindings see:
- npm: flash-fuzzy (JavaScript/TypeScript)
- PyPI: flash-fuzzy (Python)
- Maven: flash-fuzzy (Java/Kotlin/Android)
- Go module (Go)