pub struct BlockOffsetIndex {
pub entries: Arc<Vec<(OffsetMarker, u32)>>,
pub total_bytes: u32,
/* private fields */
}Fields§
§entries: Arc<Vec<(OffsetMarker, u32)>>(marker, byte_start) pairs sorted by byte_start ascending.
Wrapped in Arc so the per-edit snapshot path (which clones
BlockOffsetIndex as part of Store::snapshot) does an O(1)
pointer bump instead of an O(N) memcpy of the underlying Vec.
Mutators in this impl block go through Arc::make_mut, which
deep-clones the Vec only on the first write after the Arc has
been shared (i.e., after a snapshot was taken). External
callers see Arc<Vec<...>> which derefs transparently to
&[...] for reads.
total_bytes: u32Total byte length of the rope this index describes. The last
entry extends from its byte_start to this value.
Implementations§
Source§impl BlockOffsetIndex
impl BlockOffsetIndex
pub fn new() -> Self
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn total_bytes(&self) -> u32
pub fn set_total_bytes(&mut self, total: u32)
Sourcepub fn table_anchor_count(&self) -> usize
pub fn table_anchor_count(&self) -> usize
Number of OffsetMarker::TableAnchor entries currently indexed.
O(1) via a maintained counter. Used to gate flow-position
derivation: rope-derived positions match Block.document_position
only when this is zero.
Sourcepub fn insert_at(
&mut self,
position: usize,
marker: OffsetMarker,
byte_start: u32,
)
pub fn insert_at( &mut self, position: usize, marker: OffsetMarker, byte_start: u32, )
Insert a marker at a given byte position. The caller is
responsible for keeping the byte_start ordered relative to
neighbours — this method does NOT re-sort.
Sourcepub fn push(&mut self, marker: OffsetMarker, byte_start: u32)
pub fn push(&mut self, marker: OffsetMarker, byte_start: u32)
Append a marker at the end (its byte_start must be ≥ the last
entry’s byte_start).
Sourcepub fn push_block(&mut self, block_id: EntityId, byte_start: u32)
pub fn push_block(&mut self, block_id: EntityId, byte_start: u32)
Convenience: register a block by id. Equivalent to
push(OffsetMarker::Block(id), byte_start).
Sourcepub fn remove_at(&mut self, position: usize) -> (OffsetMarker, u32)
pub fn remove_at(&mut self, position: usize) -> (OffsetMarker, u32)
Remove the entry at the given position. Panics if out of bounds.
Sourcepub fn drain_inclusive(
&mut self,
start: usize,
end_inclusive: usize,
) -> Vec<(OffsetMarker, u32)>
pub fn drain_inclusive( &mut self, start: usize, end_inclusive: usize, ) -> Vec<(OffsetMarker, u32)>
Remove a contiguous range of entries, equivalent to
entries.drain(start..=end_inclusive) plus the matching
marker_index maintenance. Returns the removed entries.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Drop every entry and reset total_bytes to zero. Equivalent to
*self = Self::default() but expressed as a method so callers
don’t need to depend on Default.
Sourcepub fn rebuild_marker_index(&mut self)
pub fn rebuild_marker_index(&mut self)
Rebuild marker_index and table_anchor_count from entries.
Use after bulk mutations that bypassed the maintenance methods
(e.g. raw entries.push in test setup).
Sourcepub fn range_of(&self, marker: OffsetMarker) -> Option<(u32, u32)>
pub fn range_of(&self, marker: OffsetMarker) -> Option<(u32, u32)>
Byte range (start, end) of a marker. end is the next
marker’s byte_start (or total_bytes for the last entry).
Returns None if the marker is not indexed.
O(1) average via the marker_index map.
Sourcepub fn range_of_block(&self, block_id: EntityId) -> Option<(u32, u32)>
pub fn range_of_block(&self, block_id: EntityId) -> Option<(u32, u32)>
Byte range for a block-id specifically. Convenience for the common case.
Sourcepub fn range_with_successor(
&self,
marker: OffsetMarker,
) -> Option<(u32, u32, bool)>
pub fn range_with_successor( &self, marker: OffsetMarker, ) -> Option<(u32, u32, bool)>
Like range_of, but also reports whether the marker has a
successor entry. Callers that need to strip the trailing
inter-block \n boundary (e.g. block_content_via_store,
block_char_length) use this to distinguish “end == next
marker’s byte_start, with a real \n between us” from “end
== total_bytes, no separator after”.
O(1) average via marker_index.
Sourcepub fn position_of(&self, marker: OffsetMarker) -> Option<usize>
pub fn position_of(&self, marker: OffsetMarker) -> Option<usize>
Position of marker in entries. O(1) average via the
marker_index cache. Returns None if the marker is not
indexed.
Sourcepub fn marker_at_byte(&self, byte: u32) -> Option<OffsetMarker>
pub fn marker_at_byte(&self, byte: u32) -> Option<OffsetMarker>
Marker whose byte range covers byte. Returns None if the
index is empty or byte falls past total_bytes.
byte == total_bytes is treated as belonging to the last entry
(this is the cursor-at-end-of-document case).
Sourcepub fn block_at_byte(&self, byte: u32) -> Option<EntityId>
pub fn block_at_byte(&self, byte: u32) -> Option<EntityId>
Block id whose byte range covers byte, ignoring table-anchor
markers. Returns None if no block covers the byte.
Sourcepub fn byte_to_marker_byte(&self, byte: u32) -> Option<(OffsetMarker, u32)>
pub fn byte_to_marker_byte(&self, byte: u32) -> Option<(OffsetMarker, u32)>
Convert an absolute rope byte offset into
(marker, byte_in_marker). Returns None for offsets past the
end or for an empty index.
Sourcepub fn byte_to_block_byte(&self, byte: u32) -> Option<(EntityId, u32)>
pub fn byte_to_block_byte(&self, byte: u32) -> Option<(EntityId, u32)>
Block-only variant of byte_to_marker_byte.
Sourcepub fn shift_after(&mut self, threshold: u32, delta: i32)
pub fn shift_after(&mut self, threshold: u32, delta: i32)
Shift every entry whose byte_start ≥ threshold by delta
bytes, and adjust total_bytes by delta. Used after a rope
insert (positive delta) or delete (negative delta) to keep the
index in sync without a full rebuild.
entries is sorted by byte_start, so the affected suffix is
located via partition_point (O(log n)) and only that suffix
is walked.
Trait Implementations§
Source§impl Clone for BlockOffsetIndex
impl Clone for BlockOffsetIndex
Source§fn clone(&self) -> BlockOffsetIndex
fn clone(&self) -> BlockOffsetIndex
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BlockOffsetIndex
impl Debug for BlockOffsetIndex
Source§impl Default for BlockOffsetIndex
impl Default for BlockOffsetIndex
Source§fn default() -> BlockOffsetIndex
fn default() -> BlockOffsetIndex
Source§impl PartialEq for BlockOffsetIndex
impl PartialEq for BlockOffsetIndex
Source§fn eq(&self, other: &BlockOffsetIndex) -> bool
fn eq(&self, other: &BlockOffsetIndex) -> bool
self and other values to be equal, and is used by ==.