Skip to main content

LineSearch

Struct LineSearch 

Source
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

Source

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.

The larger count determines the shared upper bound. The constructor does not read either file or verify the reported mismatch.

§Errors

Returns Error::EmptyFilesCannotDiffer when both counts are zero.

§Examples
use paircomp_core::{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(true)?; // The prefixes through line 2 match.
assert_eq!(search.current_step(), LineSearchStep::CompareThroughLine { line: 3 });
search.record_result(false)?; // The prefixes through line 3 differ.
assert_eq!(search.current_step(), LineSearchStep::DifferenceAtLine { line: 3 });
Source

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.

Source

pub fn record_result(&mut self, matched: bool) -> Result<(), Error>

Applies the answer to the comparison returned by Self::current_step.

Pass true when the two fingerprints from crate::fingerprint_through_line match, or false 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.

Trait Implementations§

Source§

impl Clone for LineSearch

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for LineSearch

Source§

impl Debug for LineSearch

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for LineSearch

Source§

impl PartialEq for LineSearch

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LineSearch

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.