Skip to main content

BlockOffsetIndex

Struct BlockOffsetIndex 

Source
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: u32

Total byte length of the rope this index describes. The last entry extends from its byte_start to this value.

Implementations§

Source§

impl BlockOffsetIndex

Source

pub fn new() -> Self

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn total_bytes(&self) -> u32

Source

pub fn set_total_bytes(&mut self, total: u32)

Source

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.

Source

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.

Source

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).

Source

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).

Source

pub fn remove_at(&mut self, position: usize) -> (OffsetMarker, u32)

Remove the entry at the given position. Panics if out of bounds.

Source

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.

Source

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.

Source

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).

Source

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.

Source

pub fn range_of_block(&self, block_id: EntityId) -> Option<(u32, u32)>

Byte range for a block-id specifically. Convenience for the common case.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

pub fn byte_to_block_byte(&self, byte: u32) -> Option<(EntityId, u32)>

Block-only variant of byte_to_marker_byte.

Source

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

Source§

fn clone(&self) -> BlockOffsetIndex

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BlockOffsetIndex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BlockOffsetIndex

Source§

fn default() -> BlockOffsetIndex

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

impl Eq for BlockOffsetIndex

Source§

impl PartialEq for BlockOffsetIndex

Source§

fn eq(&self, other: &BlockOffsetIndex) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for BlockOffsetIndex

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.