Skip to main content

Crate neek_core

Crate neek_core 

Source
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§

Scorer
A reusable scorer with a fixed Prefer setting.

Constants§

MATCH_MAX_LEN
Maximum haystack/needle length that the DP scorer handles. Candidates longer than this are given SCORE_MIN by score / 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 score call 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 needle against haystack.
score_positions
Compute the fuzzy match score and fill positions with the haystack indices of the matched needle characters.

Type Aliases§

Score
Numeric type used for all scores.