pub struct LineSearch { /* private fields */ }Expand description
A deterministic search for the first differing line using file prefixes.
Construct this only after the whole-file fingerprints have been reported
as different. Supply the local line count and the count reported by the
other instance to Self::new. Drive the search with Self::current_step
and Self::record_result; the search itself performs no file I/O.
Line counts and comparison results must describe the same unchanged pair of files throughout the search. See the file stability requirements.
Implementations§
Source§impl LineSearch
impl LineSearch
Sourcepub fn new(local_line_count: u64, other_line_count: u64) -> Result<Self, Error>
pub fn new(local_line_count: u64, other_line_count: u64) -> Result<Self, Error>
Creates a line search using both copies’ counts.
Construct only after comparing the whole-file fingerprints and establishing a mismatch. Supply the local line count and the count reported by the other copy; either count may be zero. Both files must stay unchanged, and both instances must use accurate counts and the same comparison answers.
Equal counts bound the search at that count. Unequal counts bound it at one past the shorter file: the first difference is either in a shared line or at the first absent line. Comparisons never exceed the shorter count. The constructor does not read either file or verify the mismatch.
§Errors
Returns Error::EmptyFilesCannotDiffer when both counts are zero.
§Examples
use paircomp_core::{Comparison, LineSearch, LineSearchStep};
// The whole-file fingerprints differ; the copies have 3 and 4 lines.
let mut search = LineSearch::new(3, 4)?;
assert_eq!(search.current_step(), LineSearchStep::CompareThroughLine { line: 2 });
search.record_result(Comparison::Match)?;
assert_eq!(search.current_step(), LineSearchStep::CompareThroughLine { line: 3 });
search.record_result(Comparison::Differ)?;
assert_eq!(search.current_step(), LineSearchStep::DifferenceAtLine { line: 3 });Sourcepub fn current_step(&self) -> LineSearchStep
pub fn current_step(&self) -> LineSearchStep
Returns the next prefix comparison or the completed line result.
Repeated calls leave the state unchanged. Positions are 1-based; a final
result can refer to a line absent from the shorter copy. When only one
candidate remains, returns LineSearchStep::DifferenceAtLine without
requesting another comparison.
Sourcepub fn record_result(&mut self, comparison: Comparison) -> Result<(), Error>
pub fn record_result(&mut self, comparison: Comparison) -> Result<(), Error>
Applies the answer to the comparison returned by Self::current_step.
Pass Comparison::Match when the two fingerprints from
crate::fingerprint_through_line match, or Comparison::Differ when
they differ. A match excludes the prefix through the requested line; a
mismatch retains that position as a candidate. The caller must supply
the answer for the current comparison on both copies.
§Errors
Returns Error::SearchAlreadyComplete if the result is already known.
An error leaves the search unchanged.