[][src]Struct xi_rope::delta::Delta

pub struct Delta<N: NodeInfo> {
    pub els: Vec<DeltaElement<N>>,
    pub base_len: usize,
}

Represents changes to a document by describing the new document as a sequence of sections copied from the old document and of new inserted text. Deletions are represented by gaps in the ranges copied from the old document.

For example, Editing "abcd" into "acde" could be represented as: [Copy(0,1),Copy(2,4),Insert("e")]

Fields

els: Vec<DeltaElement<N>>base_len: usize

Methods

impl<N: NodeInfo> Delta<N>[src]

pub fn simple_edit<T: IntervalBounds>(
    interval: T,
    rope: Node<N>,
    base_len: usize
) -> Delta<N>
[src]

pub fn as_simple_insert(&self) -> Option<&Node<N>>[src]

If this delta represents a simple insertion, returns the inserted node.

pub fn is_simple_delete(&self) -> bool[src]

Returns true if this delta represents a single deletion without any insertions. Note that this is false for the trivial delta.

pub fn is_identity(&self) -> bool[src]

Returns true if applying the delta will cause no change.

pub fn apply(&self, base: &Node<N>) -> Node<N>[src]

Apply the delta to the given rope. May not work well if the length of the rope is not compatible with the construction of the delta.

pub fn factor(self) -> (InsertDelta<N>, Subset)[src]

Factor the delta into an insert-only delta and a subset representing deletions. Applying the insert then the delete yields the same result as the original delta:

fn test_factor(d : &Delta<RopeInfo>, r : &Rope) {
    let (ins, del) = d.clone().factor();
    let del2 = del.transform_expand(&ins.inserted_subset());
    assert_eq!(String::from(del2.delete_from(&ins.apply(r))), String::from(d.apply(r)));
}

pub fn synthesize(
    tombstones: &Node<N>,
    from_dels: &Subset,
    to_dels: &Subset
) -> Delta<N>
[src]

Synthesize a delta from a "union string" and two subsets: an old set of deletions and a new set of deletions from the union. The Delta is from text to text, not union to union; anything in both subsets will be assumed to be missing from the Delta base and the new text. You can also think of these as a set of insertions and one of deletions, with overlap doing nothing. This is basically the inverse of factor.

Since only the deleted portions of the union string are necessary, instead of requiring a union string the function takes a tombstones rope which contains the deleted portions of the union string. The from_dels subset must be the interleaving of tombstones into the union string.

fn test_synthesize(d : &Delta<RopeInfo>, r : &Rope) {
    let (ins_d, del) = d.clone().factor();
    let ins = ins_d.inserted_subset();
    let del2 = del.transform_expand(&ins);
    let r2 = ins_d.apply(&r);
    let tombstones = ins.complement().delete_from(&r2);
    let d2 = Delta::synthesize(&tombstones, &ins, &del);
    assert_eq!(String::from(d2.apply(r)), String::from(d.apply(r)));
}

pub fn summary(&self) -> (Interval, usize)[src]

Produce a summary of the delta. Everything outside the returned interval is unchanged, and the old contents of the interval are replaced by new contents of the returned length. Equations:

(iv, new_len) = self.summary()

new_s = self.apply(s)

new_s = simple_edit(iv, new_s.subseq(iv.start(), iv.start() + new_len), s.len()).apply(s)

pub fn new_document_len(&self) -> usize[src]

Returns the length of the new document. In other words, the length of the transformed string after this Delta is applied.

d.apply(r).len() == d.new_document_len()

pub fn inserts_len(&self) -> usize[src]

Returns the sum length of the inserts of the delta.

Important traits for InsertsIter<'a, N>
pub fn iter_inserts(&self) -> InsertsIter<N>[src]

Iterates over all the inserts of the delta.

Important traits for DeletionsIter<'a, N>
pub fn iter_deletions(&self) -> DeletionsIter<N>[src]

Iterates over all the deletions of the delta.

Trait Implementations

impl<N: Clone + NodeInfo> Clone for Delta<N>[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<N: NodeInfo> Debug for Delta<N> where
    Node<N>: Debug
[src]

Auto Trait Implementations

impl<N> Send for Delta<N> where
    N: Send + Sync,
    <N as NodeInfo>::L: Send + Sync

impl<N> Unpin for Delta<N>

impl<N> Sync for Delta<N> where
    N: Send + Sync,
    <N as NodeInfo>::L: Send + Sync

impl<N> UnwindSafe for Delta<N> where
    N: RefUnwindSafe,
    <N as NodeInfo>::L: RefUnwindSafe

impl<N> RefUnwindSafe for Delta<N> where
    N: RefUnwindSafe,
    <N as NodeInfo>::L: RefUnwindSafe

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]