Skip to main content

InternedInput

Struct InternedInput 

Source
pub struct InternedInput<T> {
    pub before: Vec<Token>,
    pub after: Vec<Token>,
    pub interner: Interner<T>,
}
Expand description

Two lists of interned tokens that a Diff can be computed from.

A token represents the smallest possible unit of change during a diff. For text this is usually a line, a word or a single character. All algorithms operate on interned tokens instead of using the token data directly. This allows for much better performance by amortizing the cost of hashing/equality.

While you can intern tokens yourself it is strongly recommended to use InternedInput module.

Fields§

§before: Vec<Token>

The list of interned tokens from the first sequence (before changes).

§after: Vec<Token>

The list of interned tokens from the second sequence (after changes).

§interner: Interner<T>

The interner that stores the actual token data and maps tokens to their interned IDs.

Implementations§

Source§

impl<T> InternedInput<T>

Source

pub fn clear(&mut self)

Clears all token sequences and the interner.

This removes all tokens from both the before and after sequences, as well as clearing the interner’s storage.

Note that this will not free the allocated memory.

Source§

impl<T: Eq + Hash> InternedInput<T>

Source

pub fn new<I: TokenSource<Token = T>>(before: I, after: I) -> Self

Creates a new InternedInput by tokenizing and interning two token sources.

§Parameters
  • before - The token source for the first sequence
  • after - The token source for the second sequence
§Returns

An InternedInput containing interned token sequences ready for diffing

Source

pub fn reserve_for_token_source<S: TokenSource<Token = T> + ?Sized>( &mut self, before: &S, after: &S, )

Reserve capacity so that before and after would not need to allocate if their estimate_tokens would represent an exact match of their actual tokens.

Useful for minimization of allocation before calls to update_before and update_after.

Source

pub fn reserve(&mut self, capacity_before: u32, capacity_after: u32)

Reserves capacity for the specified number of tokens in each sequence.

§Parameters
  • capacity_before - The number of tokens to reserve for the “before” sequence
  • capacity_after - The number of tokens to reserve for the “after” sequence
Source

pub fn update_before(&mut self, input: impl Iterator<Item = T>)

replaces self.before with the interned Tokens yielded by input Note that this does not erase any tokens from the interner and might therefore be considered a memory leak. If this function is called often over a long-running process consider clearing the interner with clear.

Source

pub fn update_after(&mut self, input: impl Iterator<Item = T>)

replaces self.before with the interned Tokens yielded by input Note that this does not erase any tokens from the interner and might therefore be considered a memory leak. If this function is called often over a long-running process consider clearing the interner with clear or erase_tokens_after.

Trait Implementations§

Source§

impl<T: Default> Default for InternedInput<T>

Source§

fn default() -> InternedInput<T>

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

Auto Trait Implementations§

§

impl<T> Freeze for InternedInput<T>

§

impl<T> RefUnwindSafe for InternedInput<T>
where T: RefUnwindSafe,

§

impl<T> Send for InternedInput<T>
where T: Send,

§

impl<T> Sync for InternedInput<T>
where T: Sync,

§

impl<T> Unpin for InternedInput<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for InternedInput<T>

§

impl<T> UnwindSafe for InternedInput<T>
where T: UnwindSafe,

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.