Struct similar::algorithms::IdentifyDistinct

source ·
pub struct IdentifyDistinct<Int> { /* private fields */ }
Expand description

A utility struct to convert distinct items to unique integers.

This can be helpful on larger inputs to speed up the comparisons performed by doing a first pass where the data set gets reduced to (small) integers.

The idea is that instead of passing two sequences to a diffling algorithm you first pass it via IdentifyDistinct:

use similar::capture_diff;
use similar::algorithms::{Algorithm, IdentifyDistinct};

let old = &["foo", "bar", "baz"][..];
let new = &["foo", "blah", "baz"][..];
let h = IdentifyDistinct::<u32>::new(old, 0..old.len(), new, 0..new.len());
let ops = capture_diff(
    Algorithm::Myers,
    h.old_lookup(),
    h.old_range(),
    h.new_lookup(),
    h.new_range(),
);

The indexes are the same as with the passed source ranges.

Implementations§

source§

impl<Int> IdentifyDistinct<Int>
where Int: Add<Output = Int> + From<u8> + Default + Copy,

source

pub fn new<Old, New>( old: &Old, old_range: Range<usize>, new: &New, new_range: Range<usize>, ) -> Self
where Old: Index<usize> + ?Sized, Old::Output: Eq + Hash, New: Index<usize> + ?Sized, New::Output: Eq + Hash + PartialEq<Old::Output>,

Creates an int hasher for two sequences.

source

pub fn old_lookup(&self) -> &impl Index<usize, Output = Int>

Returns a lookup for the old side.

source

pub fn new_lookup(&self) -> &impl Index<usize, Output = Int>

Returns a lookup for the new side.

source

pub fn old_range(&self) -> Range<usize>

Convenience method to get back the old range.

source

pub fn new_range(&self) -> Range<usize>

Convenience method to get back the new range.

Auto Trait Implementations§

§

impl<Int> Freeze for IdentifyDistinct<Int>

§

impl<Int> RefUnwindSafe for IdentifyDistinct<Int>
where Int: RefUnwindSafe,

§

impl<Int> Send for IdentifyDistinct<Int>
where Int: Send,

§

impl<Int> Sync for IdentifyDistinct<Int>
where Int: Sync,

§

impl<Int> Unpin for IdentifyDistinct<Int>
where Int: Unpin,

§

impl<Int> UnwindSafe for IdentifyDistinct<Int>
where Int: UnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.