pub struct OperationSeq { /* private fields */ }
Expand description
A sequence of Operation
s on text.
Implementations§
Source§impl OperationSeq
impl OperationSeq
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a store for operatations which does not need to allocate until
capacity
operations have been stored inside.
Sourcepub fn compose(&self, other: &Self) -> Result<Self, OTError>
pub fn compose(&self, other: &Self) -> Result<Self, OTError>
Merges the operation with other
into one operation while preserving
the changes of both. Or, in other words, for each input string S and a
pair of consecutive operations A and B.
apply(apply(S, A), B) = apply(S, compose(A, B))
must hold.
§Error
Returns an OTError
if the operations are not composable due to length
conflicts.
Sourcepub fn transform(&self, other: &Self) -> Result<(Self, Self), OTError>
pub fn transform(&self, other: &Self) -> Result<(Self, Self), OTError>
Transforms two operations A and B that happened concurrently and produces
two operations A’ and B’ (in an array) such that
apply(apply(S, A), B') = apply(apply(S, B), A')
.
This function is the heart of OT.
§Error
Returns an OTError
if the operations cannot be transformed due to
length conflicts.
Sourcepub fn apply(&self, s: &str) -> Result<String, OTError>
pub fn apply(&self, s: &str) -> Result<String, OTError>
Applies an operation to a string, returning a new string.
§Error
Returns an error if the operation cannot be applied due to length conflicts.
Sourcepub fn invert(&self, s: &str) -> Self
pub fn invert(&self, s: &str) -> Self
Computes the inverse of an operation. The inverse of an operation is the operation that reverts the effects of the operation, e.g. when you have an operation ‘insert(“hello “); skip(6);’ then the inverse is ‘delete(“hello “); skip(6);’. The inverse should be used for implementing undo.
Sourcepub fn base_len(&self) -> usize
pub fn base_len(&self) -> usize
Returns the length of a string these operations can be applied to
Sourcepub fn target_len(&self) -> usize
pub fn target_len(&self) -> usize
Returns the length of the resulting string after the operations have been applied.
Trait Implementations§
Source§impl Clone for OperationSeq
impl Clone for OperationSeq
Source§fn clone(&self) -> OperationSeq
fn clone(&self) -> OperationSeq
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more