pub struct RangeMap<I, V> { /* private fields */ }Expand description
Maps ranges of indices to values for efficient reverse lookups.
Stores first_index values in a sorted Vec and uses binary search to find the value for any index. The value is derived from the position.
Includes a direct-mapped cache for O(1) floor lookups when there’s locality.
Implementations§
Source§impl<I: Ord + Copy + Default + Into<usize>, V: From<usize> + Copy + Default> RangeMap<I, V>
impl<I: Ord + Copy + Default + Into<usize>, V: From<usize> + Copy + Default> RangeMap<I, V>
Sourcepub fn push(&mut self, first_index: I)
pub fn push(&mut self, first_index: I)
Push a new first_index. Value is implicitly the current length. Must be called in order (first_index must be >= all previous).
Sourcepub fn get(&mut self, index: I) -> Option<V>
pub fn get(&mut self, index: I) -> Option<V>
Floor: returns the value (position) of the largest first_index <= given index.
Sourcepub fn ceil(&self, index: I) -> Option<V>
pub fn ceil(&self, index: I) -> Option<V>
Ceil: returns the value (position) of the smallest first_index >= given index.
Shared (immutable) floor lookup — binary search only, no cache update.
Use when you only have &self (e.g. read-only clones in the query layer).
Trait Implementations§
Auto Trait Implementations§
impl<I, V> Freeze for RangeMap<I, V>
impl<I, V> RefUnwindSafe for RangeMap<I, V>where
V: RefUnwindSafe,
I: RefUnwindSafe,
impl<I, V> Send for RangeMap<I, V>
impl<I, V> Sync for RangeMap<I, V>
impl<I, V> Unpin for RangeMap<I, V>
impl<I, V> UnsafeUnpin for RangeMap<I, V>where
I: UnsafeUnpin,
V: UnsafeUnpin,
impl<I, V> UnwindSafe for RangeMap<I, V>where
V: UnwindSafe,
I: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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 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>
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