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:
| Operation | Hash map only | With SheetIndex |
|---|---|---|
| Insert 100 rows at row 20,000 | O(total cells) | O(log n + k)* |
| Delete columns B:D | O(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:
- Virtual scrolling - fetch viewport cells in microseconds
- Lazy evaluation - mark row blocks dirty without scanning
- Concurrent reads - trees are read-mostly, perfect for RwLock
- Minimal undo/redo - know exactly which vertices were touched
Implementations§
Source§impl SheetIndex
impl SheetIndex
Sourcepub fn build_from_sorted(&mut self, items: &[(PackedCoord, VertexId)])
pub fn build_from_sorted(&mut self, items: &[(PackedCoord, VertexId)])
Fast path build from sorted coordinates. Assumes items are row-major sorted.
Sourcepub fn add_vertex(&mut self, coord: PackedCoord, vertex_id: VertexId)
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
Sourcepub fn add_vertices_batch(&mut self, items: &[(PackedCoord, VertexId)])
pub fn add_vertices_batch(&mut self, items: &[(PackedCoord, VertexId)])
Add many vertices in a single pass. Assumes coords belong to same sheet index.
Sourcepub fn remove_vertex(&mut self, coord: PackedCoord, vertex_id: VertexId)
pub fn remove_vertex(&mut self, coord: PackedCoord, vertex_id: VertexId)
Sourcepub fn update_vertex(
&mut self,
old_coord: PackedCoord,
new_coord: PackedCoord,
vertex_id: VertexId,
)
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)
Sourcepub fn vertices_in_row_range(&self, start: u32, end: u32) -> Vec<VertexId>
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
Sourcepub fn vertices_in_col_range(&self, start: u32, end: u32) -> Vec<VertexId>
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
Sourcepub fn vertices_in_rect(
&self,
start_row: u32,
end_row: u32,
start_col: u32,
end_col: u32,
) -> Vec<VertexId>
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
Trait Implementations§
Source§impl Debug for SheetIndex
impl Debug for SheetIndex
Source§impl Default for SheetIndex
impl Default for SheetIndex
Source§fn default() -> SheetIndex
fn default() -> SheetIndex
Auto Trait Implementations§
impl Freeze for SheetIndex
impl RefUnwindSafe for SheetIndex
impl Send for SheetIndex
impl Sync for SheetIndex
impl Unpin for SheetIndex
impl UnwindSafe for SheetIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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