pub struct OverlapEngine A window is a fixed-width byte n-gram, and the overlap of two texts at that width is the count of one's windows that occur in the other, over whichever of the two holds more. Every query is hashed and sorted into one B-tree over every width at construction, so the sort is paid once per batch rather than once per round, and nothing is stored per candidate.
The score is asymmetric: a candidate's window occurrences count against a query's distinct windows, so swapping the two sides changes the answer whenever either repeats a window.
The fields mirror sz_overlap_engine_t one for one and only count and widths_count are read
from Rust, so the layout is load-bearing and the engine travels to C by pointer. Owning raw
pointers makes it neither Send nor Sync, which is what the C contract wants: a compute verb
grows the engine's round scratch, so it mutates, and OverlapEngine::scores takes &mut self
for that reason.
Examples
use stringzilla::{Capabilities, OverlapEngine, Stream, StringsView};
let cpu = Stream::default(Capabilities::cpu_enabled());
let mut engine = OverlapEngine::new(&["the quick brown fox"], &[4, 8], 0, &cpu).unwrap();
// A `[queries, candidates, widths]` block with the width axis unit-strided.
let mut scores = [0.0f32; 2];
let candidates = StringsView::from_slices(&["the quick brown cat"]);
cpu.scope(|scope| engine.scores(scope, candidates, None, &mut scores, 2, 2))
.unwrap();
assert!(scores.iter().all(|share| (0.0..=1.0).contains(share)));
Implements
Drop