pub struct Patch(/* private fields */);Expand description
An ordered set of Edits — the one change currency.
Invariant (debug-asserted on every Patch::push): edits are sorted
ascending and disjoint in both coordinate spaces (touching is allowed).
Implementations§
Source§impl Patch
impl Patch
Sourcepub fn push(&mut self, edit: Edit)
pub fn push(&mut self, edit: Edit)
Append an edit. Debug-panics if it breaks the ascending-disjoint invariant in either coordinate space.
Sourcepub fn map_offset(&self, offset: u32, bias: Bias) -> u32
pub fn map_offset(&self, offset: u32, bias: Bias) -> u32
Map a pre-edit byte offset to its post-edit offset (the transit table).
bias only matters when offset sits exactly on an insertion point:
Left keeps it before the inserted text, Right moves it after.
Sourcepub fn map_range(
&self,
range: Range<u32>,
start_bias: Bias,
end_bias: Bias,
) -> Range<u32>
pub fn map_range( &self, range: Range<u32>, start_bias: Bias, end_bias: Bias, ) -> Range<u32>
Map a pre-edit byte range, biasing each endpoint independently, and never inverting: if the mapped start would exceed the mapped end, both collapse to the mapped end.
Sourcepub fn map_many(&self, queries: &[(u32, Bias)], out: &mut Vec<u32>)
pub fn map_many(&self, queries: &[(u32, Bias)], out: &mut Vec<u32>)
Map a batch of offsets — each with its own Bias — through the patch,
appending results to out in query order. Semantically each entry is
exactly map_offset(offset, bias), but the batch builds a prefix-shift
index once (O(edits)) and binary-searches per query (O(log edits)), so
the whole call is O(edits + queries·log edits) instead of the
per-offset loop’s O(queries·edits). That is the difference between
O(C²) and O(C) when a document-scale multi-cursor edit produces a
C-edit patch and every derived view (C selections, N decorations, F fold
openers) must rebase through it.
No ordering precondition on queries — the binary search makes it
order-independent, so nested/overlapping ranges (decorations) are fine.