Skip to main content

ByteSearch

Struct ByteSearch 

Source
pub struct ByteSearch { /* private fields */ }
Expand description

A deterministic search for the first differing byte within a differing line.

Supply both copies’ byte lengths, including any LF, to Self::new. An absent line has length zero. Drive the search with Self::current_step and Self::record_result; the caller keeps track of the selected line, and the search itself performs no file I/O.

Counts and comparison results must describe the same unchanged pair of lines throughout the search. See the file stability requirements.

Implementations§

Source§

impl ByteSearch

Source

pub fn new(local_byte_len: u64, other_byte_len: u64) -> Result<Self, Error>

Creates a byte search using both copies’ counts.

Construct only after the line search has established that the selected line differs and all preceding lines match. Supply each copy’s byte length for that line, including any CR/LF; use zero for an absent line. Both files must stay unchanged, and both instances must use accurate lengths 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::EmptyLinesCannotDiffer when both counts are zero.

§Examples
use paircomp_core::{ByteSearch, ByteSearchStep};

// The differing lines are UTF-8 "café" and "cafè", each 5 bytes long.
let mut search = ByteSearch::new(5, 5)?;
assert_eq!(search.current_step(), ByteSearchStep::CompareThroughByte { byte: 3 });
search.record_result(true)?; // "caf" matches.
assert_eq!(search.current_step(), ByteSearchStep::CompareThroughByte { byte: 4 });
search.record_result(true)?; // The first byte of the final code point matches.
assert_eq!(search.current_step(), ByteSearchStep::DifferenceAtByte { byte: 5 });
Source

pub fn current_step(&self) -> ByteSearchStep

Returns the next prefix comparison or the completed byte result.

Repeated calls leave the state unchanged. Positions are 1-based; a final result can refer to a byte absent from the shorter copy. When only one candidate remains, returns ByteSearchStep::DifferenceAtByte 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_line_prefix match, or false when they differ. A match excludes the prefix through the requested byte; 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 ByteSearch

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 ByteSearch

Source§

impl Debug for ByteSearch

Source§

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

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

impl Eq for ByteSearch

Source§

impl PartialEq for ByteSearch

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 ByteSearch

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.