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>
impl<Int> IdentifyDistinct<Int>
sourcepub fn new<Old, New>(
old: &Old,
old_range: Range<usize>,
new: &New,
new_range: Range<usize>,
) -> Self
pub fn new<Old, New>( old: &Old, old_range: Range<usize>, new: &New, new_range: Range<usize>, ) -> Self
Creates an int hasher for two sequences.
sourcepub fn old_lookup(&self) -> &impl Index<usize, Output = Int>
pub fn old_lookup(&self) -> &impl Index<usize, Output = Int>
Returns a lookup for the old side.
sourcepub fn new_lookup(&self) -> &impl Index<usize, Output = Int>
pub fn new_lookup(&self) -> &impl Index<usize, Output = Int>
Returns a lookup for the new side.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more