Some internal refactorings
This commit is contained in:
parent
4b85e70f91
commit
34e5b3d571
8 changed files with 174 additions and 157 deletions
|
|
@ -155,34 +155,6 @@ impl DiffOp {
|
|||
}
|
||||
}
|
||||
|
||||
/// A [`DiffHook`] that captures all diff operations.
|
||||
#[derive(Default, Clone)]
|
||||
pub struct Capture(Vec<DiffOp>);
|
||||
|
||||
impl Capture {
|
||||
/// Creates a new capture hook.
|
||||
pub fn new() -> Capture {
|
||||
Capture::default()
|
||||
}
|
||||
|
||||
/// Converts the capture hook into a vector of ops.
|
||||
pub fn into_ops(self) -> Vec<DiffOp> {
|
||||
self.0
|
||||
}
|
||||
|
||||
/// Isolate change clusters by eliminating ranges with no changes.
|
||||
///
|
||||
/// This is equivalent to calling [`group_diff_ops`] on [`Capture::into_ops`].
|
||||
pub fn into_grouped_ops(self, n: usize) -> Vec<Vec<DiffOp>> {
|
||||
group_diff_ops(self.into_ops(), n)
|
||||
}
|
||||
|
||||
/// Accesses the captured operations.
|
||||
pub fn ops(&self) -> &[DiffOp] {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Isolate change clusters by eliminating ranges with no changes.
|
||||
///
|
||||
/// This will leave holes behind in long periods of equal ranges so that
|
||||
|
|
@ -272,6 +244,34 @@ pub fn get_diff_ratio(ops: &[DiffOp], old_len: usize, new_len: usize) -> f32 {
|
|||
}
|
||||
}
|
||||
|
||||
/// A [`DiffHook`] that captures all diff operations.
|
||||
#[derive(Default, Clone)]
|
||||
pub struct Capture(Vec<DiffOp>);
|
||||
|
||||
impl Capture {
|
||||
/// Creates a new capture hook.
|
||||
pub fn new() -> Capture {
|
||||
Capture::default()
|
||||
}
|
||||
|
||||
/// Converts the capture hook into a vector of ops.
|
||||
pub fn into_ops(self) -> Vec<DiffOp> {
|
||||
self.0
|
||||
}
|
||||
|
||||
/// Isolate change clusters by eliminating ranges with no changes.
|
||||
///
|
||||
/// This is equivalent to calling [`group_diff_ops`] on [`Capture::into_ops`].
|
||||
pub fn into_grouped_ops(self, n: usize) -> Vec<Vec<DiffOp>> {
|
||||
group_diff_ops(self.into_ops(), n)
|
||||
}
|
||||
|
||||
/// Accesses the captured operations.
|
||||
pub fn ops(&self) -> &[DiffOp] {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl DiffHook for Capture {
|
||||
type Error = Infallible;
|
||||
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ mod replace;
|
|||
use std::hash::Hash;
|
||||
use std::ops::{Index, Range};
|
||||
|
||||
pub use capture::*;
|
||||
pub use hook::*;
|
||||
pub use replace::*;
|
||||
pub use capture::{get_diff_ratio, group_diff_ops, Capture, DiffOp, DiffTag};
|
||||
pub use hook::DiffHook;
|
||||
pub use replace::Replace;
|
||||
|
||||
// actual diffing algorithms
|
||||
pub mod myers;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue