mod capture;
mod compact;
mod hook;
mod replace;
pub(crate) mod utils;
use std::hash::Hash;
use std::ops::{Index, Range};
use std::time::Instant;
pub use capture::Capture;
pub use compact::Compact;
pub use hook::{DiffHook, NoFinishHook};
pub use replace::Replace;
pub use utils::IdentifyDistinct;
#[doc(no_inline)]
pub use crate::Algorithm;
pub mod lcs;
pub mod myers;
pub mod patience;
pub fn diff<Old, New, D>(
alg: Algorithm,
d: &mut D,
old: &Old,
old_range: Range<usize>,
new: &New,
new_range: Range<usize>,
) -> Result<(), D::Error>
where
Old: Index<usize> + ?Sized,
New: Index<usize> + ?Sized,
D: DiffHook,
Old::Output: Hash + Eq + Ord,
New::Output: PartialEq<Old::Output> + Hash + Eq + Ord,
{
diff_deadline(alg, d, old, old_range, new, new_range, None)
}
pub fn diff_deadline<Old, New, D>(
alg: Algorithm,
d: &mut D,
old: &Old,
old_range: Range<usize>,
new: &New,
new_range: Range<usize>,
deadline: Option<Instant>,
) -> Result<(), D::Error>
where
Old: Index<usize> + ?Sized,
New: Index<usize> + ?Sized,
D: DiffHook,
Old::Output: Hash + Eq + Ord,
New::Output: PartialEq<Old::Output> + Hash + Eq + Ord,
{
match alg {
Algorithm::Myers => myers::diff_deadline(d, old, old_range, new, new_range, deadline),
Algorithm::Patience => patience::diff_deadline(d, old, old_range, new, new_range, deadline),
Algorithm::Lcs => lcs::diff_deadline(d, old, old_range, new, new_range, deadline),
}
}
pub fn diff_slices<D, T>(alg: Algorithm, d: &mut D, old: &[T], new: &[T]) -> Result<(), D::Error>
where
D: DiffHook,
T: Eq + Hash + Ord,
{
diff(alg, d, old, 0..old.len(), new, 0..new.len())
}
pub fn diff_slices_deadline<D, T>(
alg: Algorithm,
d: &mut D,
old: &[T],
new: &[T],
deadline: Option<Instant>,
) -> Result<(), D::Error>
where
D: DiffHook,
T: Eq + Hash + Ord,
{
diff_deadline(alg, d, old, 0..old.len(), new, 0..new.len(), deadline)
}