SortedIndex

Struct SortedIndex 

Source
pub struct SortedIndex<'a> { /* private fields */ }
Expand description

A sorted index over a borrowed slice of Values.

Keys are extracted from each value using a set of Projections. The index is sorted using a private total ordering on Value that extends the existing PartialOrd (which has SQL semantics and returns None for Null comparisons) with a deterministic order for all cases.

Supports equality and range queries. Duplicate keys are allowed; queries that would return multiple values (e.g. find_range) yield all of them.

Construction is O(n log n). All queries are O(log n + k) where k is the result count.

§Cloning

Key fields are cloned into owned Values for storage. Full records are never cloned — the stored values are &'a Value references into the source slice.

Implementations§

Source§

impl<'a> SortedIndex<'a>

Source

pub fn new(values: &'a [Value], projections: &[Projection]) -> Self

Build a sorted index over values, keyed by the fields selected by projections.

Each projection navigates into a value to extract one key component. Multiple projections produce a composite key compared lexicographically.

Source

pub fn find_eq(&self, key: &[Value]) -> Option<&'a Value>

Find the value whose key equals key.

Source

pub fn find_lt(&self, key: &[Value]) -> impl Iterator<Item = &'a Value> + '_

Iterate over all values whose key is strictly less than key.

Source

pub fn find_le(&self, key: &[Value]) -> impl Iterator<Item = &'a Value> + '_

Iterate over all values whose key is less than or equal to key.

Source

pub fn find_gt(&self, key: &[Value]) -> impl Iterator<Item = &'a Value> + '_

Iterate over all values whose key is strictly greater than key.

Source

pub fn find_ge(&self, key: &[Value]) -> impl Iterator<Item = &'a Value> + '_

Iterate over all values whose key is greater than or equal to key.

Source

pub fn find_range( &self, lower: Bound<&[Value]>, upper: Bound<&[Value]>, ) -> impl Iterator<Item = &'a Value> + '_

Iterate over all values whose key falls within [lower, upper] using Bound to control inclusive/exclusive/unbounded endpoints.

Auto Trait Implementations§

§

impl<'a> Freeze for SortedIndex<'a>

§

impl<'a> RefUnwindSafe for SortedIndex<'a>

§

impl<'a> Send for SortedIndex<'a>

§

impl<'a> Sync for SortedIndex<'a>

§

impl<'a> Unpin for SortedIndex<'a>

§

impl<'a> UnwindSafe for SortedIndex<'a>

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

Source§

type Output = T

Should always be Self
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.
§

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

§

fn vzip(self) -> V