pub struct SelectionVector { /* private fields */ }Expand description
A selection vector tracks qualifying row indices
This is the core data structure for late materialization. Instead of copying row data, we track which row indices qualify and only materialize when needed.
§Memory Layout
Uses u32 indices (4 bytes each) instead of full rows (potentially
hundreds of bytes each). For a 1M row table filtered to 10K rows:
- Old: 1M × sizeof(Row) = potentially gigabytes
- New: 10K × 4 bytes = 40KB
§Example
// Create from filter bitmap
let selection = SelectionVector::from_bitmap(&[true, false, true, true, false]);
assert_eq!(selection.len(), 3);
assert_eq!(selection.indices(), &[0, 2, 3]);
// Iterate over qualifying indices
for idx in selection.iter() {
let row = &source_rows[idx as usize];
// Process row...
}Implementations§
Source§impl SelectionVector
impl SelectionVector
Sourcepub fn all(count: usize) -> Self
pub fn all(count: usize) -> Self
Create a selection vector that selects all rows in range [0, count)
Sourcepub fn from_range(range: Range<usize>) -> Self
pub fn from_range(range: Range<usize>) -> Self
Create a selection vector from a range
Sourcepub fn from_indices(indices: Vec<u32>) -> Self
pub fn from_indices(indices: Vec<u32>) -> Self
Create from pre-computed indices (assumes sorted, unique)
Sourcepub fn from_bitmap(bitmap: &[bool]) -> Self
pub fn from_bitmap(bitmap: &[bool]) -> Self
Create from a boolean filter bitmap
This is the most common creation path after evaluating predicates.
§Example
let bitmap = vec![true, false, true, true, false];
let selection = SelectionVector::from_bitmap(&bitmap);
assert_eq!(selection.indices(), &[0, 2, 3]);Sourcepub fn from_bitmap_with_capacity(bitmap: &[bool], capacity_hint: usize) -> Self
pub fn from_bitmap_with_capacity(bitmap: &[bool], capacity_hint: usize) -> Self
Create from a bitmap with pre-allocated capacity hint
Use when you have an estimate of how many rows will match.
Sourcepub fn into_indices(self) -> Vec<u32>
pub fn into_indices(self) -> Vec<u32>
Consume and return the indices vector
Sourcepub fn intersect(&self, other: &SelectionVector) -> SelectionVector
pub fn intersect(&self, other: &SelectionVector) -> SelectionVector
Intersect with another selection vector (AND operation)
Returns indices that appear in both selections. Useful for combining multiple filter conditions.
Sourcepub fn union(&self, other: &SelectionVector) -> SelectionVector
pub fn union(&self, other: &SelectionVector) -> SelectionVector
Union with another selection vector (OR operation)
Returns indices that appear in either selection.
Sourcepub fn remap(&self, base: &SelectionVector) -> SelectionVector
pub fn remap(&self, base: &SelectionVector) -> SelectionVector
Remap indices through another selection
If self contains indices [0, 2, 3] and base contains [10, 20, 30, 40, 50],
returns [10, 30, 40] (indices 0, 2, 3 from base).
This is used when chaining operations: if we filter a filtered result, we need to map back to original row indices.
Sourcepub fn to_bitmap(&self, total_count: usize) -> Vec<bool>
pub fn to_bitmap(&self, total_count: usize) -> Vec<bool>
Create a dense bitmap representation
Returns a boolean vector where result[i] = true iff i is in the selection.
total_count is the total number of rows in the source.
Sourcepub fn filter<T, F>(&self, data: &[T], predicate: F) -> SelectionVector
pub fn filter<T, F>(&self, data: &[T], predicate: F) -> SelectionVector
Filter this selection based on a predicate applied to a slice of data
This is useful for applying additional filters without materializing rows.
Sourcepub fn map<T, F>(&self, f: F) -> Vec<T>
pub fn map<T, F>(&self, f: F) -> Vec<T>
Apply a function to each selected index, collecting results
Sourcepub fn selectivity(&self, total_count: usize) -> f64
pub fn selectivity(&self, total_count: usize) -> f64
Selectivity ratio (selected / total)
Returns a value between 0.0 and 1.0 indicating what fraction of the total rows are selected.
Sourcepub fn is_contiguous(&self) -> bool
pub fn is_contiguous(&self) -> bool
Compact representation check
Returns true if this selection represents a contiguous range, which allows for more efficient processing.
Trait Implementations§
Source§impl Clone for SelectionVector
impl Clone for SelectionVector
Source§fn clone(&self) -> SelectionVector
fn clone(&self) -> SelectionVector
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SelectionVector
impl Debug for SelectionVector
Source§impl Default for SelectionVector
impl Default for SelectionVector
Source§impl<'a> IntoIterator for &'a SelectionVector
impl<'a> IntoIterator for &'a SelectionVector
Auto Trait Implementations§
impl Freeze for SelectionVector
impl RefUnwindSafe for SelectionVector
impl Send for SelectionVector
impl Sync for SelectionVector
impl Unpin for SelectionVector
impl UnwindSafe for SelectionVector
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
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>
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>
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