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.
§Examples
use toasty_core::stmt::{SortedIndex, Projection, Value};
let records = vec![
Value::record_from_vec(vec![Value::from(3_i64), Value::from("c")]),
Value::record_from_vec(vec![Value::from(1_i64), Value::from("a")]),
Value::record_from_vec(vec![Value::from(2_i64), Value::from("b")]),
];
let index = SortedIndex::new(&records, &[Projection::single(0)]);
let found = index.find_eq(&[Value::from(2_i64)]);
assert!(found.is_some());Implementations§
Source§impl<'a> SortedIndex<'a>
impl<'a> SortedIndex<'a>
Sourcepub fn new(values: &'a [Value], projections: &[Projection]) -> Self
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.
Sourcepub fn find_lt(&self, key: &[Value]) -> impl Iterator<Item = &'a Value> + '_
pub fn find_lt(&self, key: &[Value]) -> impl Iterator<Item = &'a Value> + '_
Iterate over all values whose key is strictly less than key.
Sourcepub fn find_le(&self, key: &[Value]) -> impl Iterator<Item = &'a Value> + '_
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.
Sourcepub fn find_gt(&self, key: &[Value]) -> impl Iterator<Item = &'a Value> + '_
pub fn find_gt(&self, key: &[Value]) -> impl Iterator<Item = &'a Value> + '_
Iterate over all values whose key is strictly greater than key.