Skip to main content

FoldIndex

Struct FoldIndex 

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

Sorted in canonical (start_row ASC, end_row DESC) order over a fold slice for O(log F) “is this row hidden by a closed fold” queries.

The O(log F) twin of folds.iter().any(|f| f.hides(row)). Closed folds’ (start_row, end_row] hidden ranges are merged into a disjoint union, and one partition_point over the merged ranges answers the query. Merging (not just sorting) is what keeps this correct for nested folds: a fold that starts inside an enclosing one can end before it while the enclosing fold still covers the query row, so “the last fold with start_row <= row” alone is not enough — that fold may have already ended while an earlier, longer one still hides the row.

Mirrors the TUI renderer’s FoldIndex (hjkl-buffer-tui render.rs) — the same merge, the same query, the same answers. That copy sorts its input defensively because its fold source is not guaranteed ordered; this one relies on the buffer’s canonical (start_row ASC, end_row DESC) ordering invariant (see crate::View::add_fold and crate::View::set_auto_folds) and skips the sort so the build stays O(F) — it runs per keystroke / per frame on hot paths. Debug builds assert the invariant, so feeding unsorted folds fails loudly in tests rather than silently mis-answering in release.

Implementations§

Source§

impl FoldIndex

Source

pub fn new(folds: &[Fold]) -> Self

Build the merged hidden-range index from a fold slice in canonical (start_row ASC, end_row DESC) order (the buffer invariant — see the type docs).

O(F): one filter pass over the folds, then a single merge pass.

Source

pub fn hides_row(&self, row: usize) -> bool

True when row is hidden by a closed fold — the O(log F) twin of folds.iter().any(|f| f.hides(row)).

Trait Implementations§

Source§

impl Clone for FoldIndex

Source§

fn clone(&self) -> FoldIndex

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 FoldIndex

Source§

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

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

impl Eq for FoldIndex

Source§

impl PartialEq for FoldIndex

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FoldIndex

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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.