pub struct Scorer { /* private fields */ }Expand description
A reusable scorer with a fixed Prefer setting.
Construct once and call Scorer::score / Scorer::score_positions for
each candidate. All three algorithms share the same Gotoh DP core; only
the gap-penalty constants differ.
The free functions score and score_positions are thin wrappers
around Scorer::default() (i.e. Prefer::Contiguous).
§Examples
use neek_core::{Scorer, config::Prefer};
// Prefer matches that start early in each candidate.
let scorer = Scorer::new(Prefer::Prefix);
assert!(scorer.score(b"bl", b"build") > scorer.score(b"bl", b"table"));
// Prefer matches that end late in each candidate.
let scorer = Scorer::new(Prefer::Suffix);
assert!(scorer.score(b"le", b"cable") > scorer.score(b"le", b"label"));Implementations§
Source§impl Scorer
impl Scorer
Sourcepub fn score_positions(
self,
needle: &[u8],
haystack: &[u8],
positions: &mut [usize],
) -> Score
pub fn score_positions( self, needle: &[u8], haystack: &[u8], positions: &mut [usize], ) -> Score
Compute the fuzzy match score and fill positions with the haystack
indices of the matched needle characters.
positions must have length >= needle.len(). On return, positions[i]
is the haystack index of the character matched to needle[i], in
strictly increasing order.
Returns the same score as Scorer::score would for the same inputs.
§Allocation
Allocates two Vec<MaybeUninit<f64>> of size
needle.len() × MATCH_MAX_LEN for the full DP matrices required by
backtracking.