Skip to main content

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,
    pub segmentation: Segmentation,
    pub word_mode: bool,
}

Fields§

§diff_timeout: Option<f32>§edit_cost: i32§match_distance: i32§patch_margin: i32§match_maxbits: i32§match_threshold: f32§patch_delete_threshold: f32§segmentation: Segmentation§word_mode: bool

Implementations§

Source§

impl Dmp

Source

pub fn diff_xindex(&mut self, diffs: &Vec<Diff>, loc: i32) -> i32

loc is a location in text1, compute and return the equivalent location in text2. e.g. “The cat” vs “The big cat”, 1->1, 5->8

Args: diffs: Vector of diff object. loc: Location within text1.

Returns: Location within text2.

Source

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

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

Args: diffs: Vectoe of diff object.

Returns: Source text.

Source

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

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

Args: diffs: Vector of diff object.

Returns: destination text.

Source

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

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

Args: diffs: Vector of diff object.

Returns: Number of changes.

Source§

impl Dmp

Source

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

Source

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

Source

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

Source

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

Source§

impl Dmp

Source

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

Crush the diff into an encoded string which describes the operations required to transform text1 into text2. E.g. =3\t-2\t+ing -> Keep 3 chars, delete 2 chars, insert ‘ing’. Operations are tab-separated. Inserted text is escaped using %xx notation.

Args: diffs: Vector of diff object.

Returns: Delta text.

Source

pub fn diff_from_delta(&mut self, text1: &str, delta: &str) -> Vec<Diff>

Given the original text1, and an encoded string which describes the operations required to transform text1 into text2, compute the full diff.

Args: text1: Source string for the diff. delta: Delta text.

Returns: Vector of diff object.

Panics on invalid input (malformed escape, bad length, or a delta that does not consume text1 exactly).

Source§

impl Dmp

Source

pub fn diff_main( &mut 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. Returns: Vector of diffs as changes.

Source

pub fn diff_linemode( &mut self, text1: &Vec<char>, text2: &Vec<char>, ) -> Vec<Diff>

Do a quick line-level diff on both chars, then rediff the parts for greater accuracy. This speedup can produce non-minimal diffs.

Args: text1: Old chars to be diffed. text2: New chars to be diffed.

Returns: Vector of diffs as changes.

Source

pub fn diff_bisect(&mut self, char1: &Vec<char>, char2: &Vec<char>) -> Vec<Diff>

Find the ‘middle snake’ of a diff, split the problem in two and return the recursively constructed diff. See Myers 1986 paper: An O(ND) Difference Algorithm and Its Variations.

Args: text1: Old chars to be diffed. text2: New chars to be diffed.

Returns: Vector of diffs as changes.

Source

pub fn diff_common_prefix( &mut self, text1: &Vec<char>, text2: &Vec<char>, ) -> i32

Source

pub fn diff_common_suffix( &mut self, text1: &Vec<char>, text2: &Vec<char>, ) -> i32

Source

pub fn diff_common_overlap( &mut self, text1: &Vec<char>, text2: &Vec<char>, ) -> i32

Source

pub fn diff_half_match( &mut self, text1: &Vec<char>, text2: &Vec<char>, ) -> Vec<String>

Do the two texts share a substring which is at least half the length of the longer text? This speedup can produce non-minimal diffs.

Returns: Five element Vector, containing the prefix of text1, the suffix of text1, the prefix of text2, the suffix of text2 and the common middle. Or empty vector if there was no match.

Source§

impl Dmp

Source

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

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.

Returns: Best match index or -1.

Source

pub fn match_bitap( &mut self, text: &Vec<char>, patern: &Vec<char>, loc: i32, ) -> i32

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

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

Returns: Best match index or -1.

Source

pub fn match_bitap_score( &mut self, e: i32, x: i32, loc: i32, patern: &Vec<char>, ) -> f32

Compute and return the score for a match with e errors and x location. Accesses loc and pattern through being a closure.

Args: e: Number of errors in match. x: Location of match.

Returns: Overall score for match (0.0 = good, 1.0 = bad).

Source

pub fn match_alphabet(&mut self, patern: &Vec<char>) -> HashMap<char, i32>

Initialise the alphabet for the Bitap algorithm.

Args: pattern: The text to encode.

Returns: Hash of character locations. Public i32 view of the internal u64 masks; bit 31 lands in the sign bit exactly as the pre-rewrite release builds computed it.

Source§

impl Dmp

Source

pub fn patch_add_context(&mut self, patch: &mut Patch, text: &mut Vec<char>)

Increase the context until it is unique, but don’t let the pattern expand beyond Match_MaxBits.

Args: patch: The patch to grow. text: Source text.

Source

pub fn patch_make1(&mut 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. Returns: Vector of Patch objects.

Source

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

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

Args: diffs: Vector od diff object. Returns: Vector of Patch objects.

Source

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

Compute a list of patches to turn text1 into text2.

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

Returns: Vector of Patch objects.

Source

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

Compute a list of patches to turn text1 into text2.

Args: text1: First string. diffs: Vector of diff object. Returns: Array of Patch objects.

Source

pub fn patch_deep_copy(&mut self, patches: &mut Vec<Patch>) -> Vec<Patch>

Given an Vector of patches, return another Vector that is identical.

Args: patches: Vector of Patch objects.

Returns: Vector of Patch objects.

Source

pub fn patch_apply( &mut self, patches: &mut Vec<Patch>, source_text: &str, ) -> (Vec<char>, Vec<bool>)

Source

pub fn patch_add_padding(&mut self, patches: &mut Vec<Patch>) -> Vec<char>

Add some padding on text start and end so that edges can match something. Intended to be called only from within patch_apply.

Args: patches: Array of Patch objects.

Returns: The padding chars added to each side.

Source

pub fn patch_splitmax(&mut self, patches: &mut Vec<Patch>)

Look through the patches and break up any which are longer than the maximum limit of the match algorithm. Intended to be called only from within patch_apply.

Args: patches: Array of Patch objects.

Source

pub fn patch_to_text(&mut self, patches: &mut Vec<Patch>) -> String

Take a list of patches and return a textual representation.

Args: patches: Vector of Patch objects.

Returns: Text representation of patches.

Source

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

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

Args: textline: Text representation of patches.

Returns: Vector of Patch objects.

Panics on malformed patch text.

Source

pub fn patch1_from_text(&mut self, textline: String) -> Patch

Source§

impl Dmp

Source

pub fn split_by_char(&mut self, text: &str, ch: char) -> Vec<String>

split the string accoring to given character

Args: text: string we have to split ch: character by which we have to split string

Returns: Vector of string after spliting according to character.

Source

pub fn split_by_chars(&mut self, text: &str) -> Vec<String>

split the string accoring to given characters “@@ “.

Args: text: string we have to split

Returns: Vector of string after spliting according to characters.

Source§

impl Dmp

Source

pub fn diff_words_tochars( &mut self, text1: &String, text2: &String, ) -> (String, String, Vec<String>)

Source

pub fn diff_words_tochars_munge( &mut self, text: &String, wordarray: &mut Vec<String>, wordhash: &mut HashMap<String, u32>, ) -> String

Source

pub fn diff_lines_tochars( &mut self, text1: &Vec<char>, text2: &Vec<char>, ) -> (String, String, Vec<String>)

Source

pub fn diff_lines_tochars_munge( &mut self, text: &Vec<char>, linearray: &mut Vec<String>, linehash: &mut HashMap<String, i32>, ) -> String

Source

pub fn diff_chars_tolines( &mut self, diffs: &mut Vec<Diff>, line_array: &Vec<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§

impl Dmp

Source

pub fn new() -> Self

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 UnsafeUnpin 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.