pub struct LineIndex { /* private fields */ }Expand description
Pre-computed line starts for O(log n) line/column lookup.
Build once per document, then use for all position lookups. This is essential for efficient parsing of documents with many OFM elements.
§Example
use turbovault_core::{LineIndex, SourcePosition};
let content = "Line 1\nLine 2\nLine 3";
let index = LineIndex::new(content);
// O(log n) lookup instead of O(n)
let pos = SourcePosition::from_offset_indexed(&index, 7, 6);
assert_eq!(pos.line, 2);
assert_eq!(pos.column, 1);Implementations§
Source§impl LineIndex
impl LineIndex
Sourcepub fn line_col(&self, offset: usize) -> (usize, usize)
pub fn line_col(&self, offset: usize) -> (usize, usize)
Get (line, column) for a byte offset in O(log n) via binary search.
Line numbers start at 1, column numbers start at 1.
Sourcepub fn line_start(&self, line: usize) -> Option<usize>
pub fn line_start(&self, line: usize) -> Option<usize>
Get the byte offset where a line starts.
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Get total number of lines.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LineIndex
impl RefUnwindSafe for LineIndex
impl Send for LineIndex
impl Sync for LineIndex
impl Unpin for LineIndex
impl UnwindSafe for LineIndex
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
Mutably borrows from an owned value. Read more