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,
impl<Int> IdentifyDistinct<Int>where
Int: Add<Output = Int> + From<u8> + Default + Copy,
sourcepub fn new<Old, New>(
old: &Old,
old_range: Range<usize>,
new: &New,
new_range: Range<usize>
) -> Selfwhere
Old: Index<usize> + ?Sized,
Old::Output: Eq + Hash,
New: Index<usize> + ?Sized,
New::Output: Eq + Hash + PartialEq<Old::Output>,
pub fn new<Old, New>(
old: &Old,
old_range: Range<usize>,
new: &New,
new_range: Range<usize>
) -> Selfwhere
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.
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.