Dmp

Struct Dmp 

Source
pub struct Dmp {
    pub diff_timeout: Option<f32>,
    pub edit_cost: i32,
    pub match_distance: i32,
    pub patch_margin: i32,
    pub match_maxbits: i32,
    pub match_threshold: f32,
    pub patch_delete_threshold: f32,
}

Fields§

§diff_timeout: Option<f32>

Number of seconds to map a diff before giving up (None for infinity).

§edit_cost: i32

Cost of an empty edit operation in terms of edit characters.

§match_distance: i32

How far to search for a match (0 = exact location, 1000+ = broad match). A match this many characters away from the expected location will add 1.0 to the score (0.0 is a perfect match).

§patch_margin: i32

Chunk size for context length.

§match_maxbits: i32

The number of bits in an int. Python has no maximum, thus to disable patch splitting set to 0. However to avoid long patches in certain pathological cases, use 32. Multiple short patches (using native ints) are much faster than long ones.

§match_threshold: f32

At what point is no match declared (0.0 = perfection, 1.0 = very loose).

§patch_delete_threshold: f32

When deleting a large block of text (over ~64 characters), how close do the contents have to be to match the expected contents. (0.0 = perfection, 1.0 = very loose). Note that match_threshold controls how closely the end points of a delete need to match.

Implementations§

Source§

impl Dmp

Source

pub fn diff_main(&self, text1: &str, text2: &str, checklines: bool) -> Vec<Diff>

Find the differences between two chars. Simplifies the problem by stripping any common prefix or suffix off the texts before diffing.

§Args
  • text1: Old chars to be diffed.
  • text2: New chars to be diffed.
  • checklines: Optional speedup flag. If present and false, then don’t run a line-level diff first to identify the changed areas. Defaults to true, which does a faster, slightly less optimal diff.
§Return

Vector of diffs as changes.

Source

pub fn diff_chars_tolines(&self, diffs: &mut Vec<Diff>, line_array: &[String])

Rehydrate the text in a diff from a string of line hashes to real lines of text.

Args

  • diffs: Vector of diffs as changes.
  • lineArray: Vector of unique strings.
Source

pub fn diff_cleanup_semantic(&self, diffs: &mut Vec<Diff>)

Reduce the number of edits by eliminating semantically trivial equalities.

§Args
  • diffs: Vectors of diff object.
Source

pub fn diff_cleanup_semantic_lossless(&self, diffs: &mut Vec<Diff>)

Look for single edits surrounded on both sides by equalities which can be shifted sideways to align the edit to a word boundary. e.g: The cat came. -> The cat came.

Args:

  • diffs: Vector of diff object.
Source

pub fn diff_cleanup_efficiency(&self, diffs: &mut Vec<Diff>)

Reduce the number of edits by eliminating operationally trivial equalities.

§Args
  • diffs: Vector of diff object.
Source

pub fn diff_cleanup_merge(&self, diffs: &mut Vec<Diff>)

Reorder and merge like edit sections. Merge equalities. Any edit section can move as long as it doesn’t cross an equality.

§Args
  • diffs: vectors of diff object.
Source

pub fn diff_text1(&self, diffs: &Vec<Diff>) -> String

Compute and return the source text (all equalities and deletions).

§Args
  • diffs: Vector of diff object.
§Return

Source text.

Source

pub fn diff_text2(&self, diffs: &mut Vec<Diff>) -> String

Compute and return the destination text (all equalities and insertions).

§Args
  • diffs: Vector of diff object.
§Return

Destination text.

Source

pub fn diff_levenshtein(&self, diffs: &Vec<Diff>) -> i32

Compute the Levenshtein distance; the number of inserted, deleted or substituted characters.

§Args
  • diffs: Vector of diff object.
§Return

Number of changes.

Source

pub fn match_main( &self, text1: &str, patern1: &str, loc: i32, ) -> Result<i32, Error>

Locate the best instance of ‘pattern’ in ‘text’ near ‘loc’.

§Args
  • text: The text to search.
  • pattern: The pattern to search for.
  • loc: The location to search around.
§Return

Best match index or -1.

Source

pub fn patch_make1(&self, text1: &str, text2: &str) -> Vec<Patch>

Compute a list of patches to turn text1 into text2. compute diffs.

§Args
  • text1: First string.
  • text2: Second string.
§Return

Vector of Patch objects.

Source

pub fn patch_make2(&self, diffs: &Vec<Diff>) -> Vec<Patch>

Compute a list of patches to turn text1 into text2. Use diffs to compute first text.

§Args
  • diffs: Vector of diff object.
§Return

Vector of Patch objects.

Source

pub fn patch_make3( &self, text1: &str, _text2: &str, diffs: &[Diff], ) -> Vec<Patch>

Compute a list of patches to turn text1 into text2.

§Args
  • text1: First string.
  • text2: Second string.
  • diffs: Vector of diff.
§Return

Vector of Patch objects.

Source

pub fn patch_make4(&self, text1: &str, diffs: &[Diff]) -> Vec<Patch>

Compute a list of patches to turn text1 into text2.

§Args
  • text1: First string.
  • diffs: Vector of diff object.
§Return

Array of Patch objects.

Source

pub fn patch_apply( &self, patches: &[Patch], source_text: &str, ) -> Result<(Vec<char>, Vec<bool>), Error>

Merge a set of patches onto the text. Return a patched text, as well as a list of true/false values indicating which patches were applied.

§Args
  • patches: Vector of Patch objects.
  • text: Old text.
§Return

Two element Vector, containing the new chars and an Vector of boolean values.

Source

pub fn patch_to_text(&self, patches: &[Patch]) -> String

Take a list of patches and return a textual representation.

§Args
  • patches: Vector of Patch objects.
§Return

Text representation of patches.

Source

pub fn patch_from_text(&self, textline: String) -> Result<Vec<Patch>, Error>

Parse a textual representation of patches and return a list of patch objects.

§Args
  • textline: Text representation of patches.
§Return

Vector of Patch objects or error in case of invalid input.

Source

pub fn patch1_from_text(&self, textline: String) -> Result<Patch, Error>

Trait Implementations§

Source§

impl Default for Dmp

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Dmp

§

impl RefUnwindSafe for Dmp

§

impl Send for Dmp

§

impl Sync for Dmp

§

impl Unpin for Dmp

§

impl UnwindSafe for Dmp

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>,

Source§

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>,

Source§

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.