SheetIndex

Struct SheetIndex 

Source
pub struct SheetIndex { /* private fields */ }
Expand description

Sheet-level sparse index for efficient range queries on vertex positions.

§Why SheetIndex with interval trees?

While cell_to_vertex: HashMap<CellRef, VertexId> provides O(1) exact lookups, structural operations (insert/delete rows/columns) need to find ALL vertices in a given range, which would require O(n) full scans of the hash map.

§Performance comparison:

OperationHash map onlyWith SheetIndex
Insert 100 rows at row 20,000O(total cells)O(log n + k)*
Delete columns B:DO(total cells)O(log n + k)
Viewport query (visible cells)O(total cells)O(log n + k)

*where n = number of indexed vertices, k = vertices actually affected

§Memory efficiency:

  • Each interval is just 2×u32 + Vec pointer
  • Spreadsheets are extremely sparse (1M row sheet typically has <10K cells)
  • Point intervals (single cells) are the common case
  • Trees stay small and cache-friendly

§Future benefits:

  1. Virtual scrolling - fetch viewport cells in microseconds
  2. Lazy evaluation - mark row blocks dirty without scanning
  3. Concurrent reads - trees are read-mostly, perfect for RwLock
  4. Minimal undo/redo - know exactly which vertices were touched

Implementations§

Source§

impl SheetIndex

Source

pub fn new() -> Self

Create a new empty sheet index

Source

pub fn build_from_sorted(&mut self, items: &[(PackedCoord, VertexId)])

Fast path build from sorted coordinates. Assumes items are row-major sorted.

Source

pub fn add_vertex(&mut self, coord: PackedCoord, vertex_id: VertexId)

Add a vertex at the given coordinate to the index.

§Complexity

O(log n) where n is the number of vertices in the index

Source

pub fn add_vertices_batch(&mut self, items: &[(PackedCoord, VertexId)])

Add many vertices in a single pass. Assumes coords belong to same sheet index.

Source

pub fn remove_vertex(&mut self, coord: PackedCoord, vertex_id: VertexId)

Remove a vertex from the index.

§Complexity

O(log n) where n is the number of vertices in the index

Source

pub fn update_vertex( &mut self, old_coord: PackedCoord, new_coord: PackedCoord, vertex_id: VertexId, )

Update a vertex’s position in the index (move operation).

§Complexity

O(log n) for removal + O(log n) for insertion = O(log n)

Source

pub fn vertices_in_row_range(&self, start: u32, end: u32) -> Vec<VertexId>

Query all vertices in the given row range.

§Complexity

O(log n + k) where k is the number of vertices in the range

Source

pub fn vertices_in_col_range(&self, start: u32, end: u32) -> Vec<VertexId>

Query all vertices in the given column range.

§Complexity

O(log n + k) where k is the number of vertices in the range

Source

pub fn vertices_in_rect( &self, start_row: u32, end_row: u32, start_col: u32, end_col: u32, ) -> Vec<VertexId>

Query all vertices in a rectangular range.

§Complexity

O(log n + k) where k is the number of vertices in the range

Source

pub fn len(&self) -> usize

Get the total number of indexed vertices (may count duplicates if vertex appears at multiple positions).

Source

pub fn is_empty(&self) -> bool

Check if the index is empty.

Source

pub fn clear(&mut self)

Clear all entries from the index.

Trait Implementations§

Source§

impl Debug for SheetIndex

Source§

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

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

impl Default for SheetIndex

Source§

fn default() -> SheetIndex

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

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,