Expand description
Fuzzy matching and scoring engine.
§Quick start
use neek_core::{has_match, score, score_positions};
let needle = b"src";
let haystack = b"src/main.rs";
assert!(has_match(needle, haystack));
let s = score(needle, haystack);
println!("score: {s}");
let mut positions = vec![0usize; needle.len()];
let s2 = score_positions(needle, haystack, &mut positions);
assert_eq!(s, s2);
println!("matched at positions: {:?}", positions);§Configurable scoring
The default free functions use config::Prefer::Contiguous, which
rewards consecutive character runs (Gotoh DP with balanced gap penalties).
To prefer prefix or suffix matches, construct a Scorer and use its
methods:
use neek_core::{Scorer, config::Prefer};
let scorer = Scorer::new(Prefer::Prefix);
// "build" starts with 'b'; "table" has a contiguous "bl" mid-string.
// Prefix-biased scoring ranks "build" higher.
assert!(scorer.score(b"bl", b"build") > scorer.score(b"bl", b"table"));Re-exports§
pub use config::Prefer;
Modules§
- config
- Scoring constants and algorithm configuration.
Structs§
Constants§
- MATCH_
MAX_ LEN - Maximum haystack/needle length that the DP scorer handles. Candidates
longer than this are given
SCORE_MINbyscore/score_positions. - SCORE_
MAX - Returned when a candidate is an exact (case-insensitive) match for the needle, or when the needle is empty and all candidates match trivially.
- SCORE_
MIN - Returned when a candidate cannot be scored (too long, no match, or the
needle is empty at the
scorecall site).
Functions§
- has_
match - Uses
memchr::memchr2(SIMD-accelerated via SSE4.2/AVX2 on x86-64) for the per-character scan. - score
- Compute the fuzzy match score of
needleagainsthaystack. - score_
positions - Compute the fuzzy match score and fill
positionswith the haystack indices of the matched needle characters.
Type Aliases§
- Score
- Numeric type used for all scores.