pub struct Selection { /* private fields */ }Expand description
Which positions of a vector are still in play, as indices into it.
An empty selection means nothing survived, which is different from no selection at all. The
distinction is why this is a type rather than an Option<Vec<u32>> that everybody interprets
slightly differently.
Implementations§
Source§impl Selection
impl Selection
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
A selection of nothing, with room for capacity positions.
Sourcepub fn identity(len: usize) -> Self
pub fn identity(len: usize) -> Self
A selection of the first len positions in order.
Materialized rather than represented as an absent selection, so this is what a caller uses when it genuinely wants the identity written down. A scan that has not filtered anything carries no selection at all, which is cheaper and is the common case.
Sourcepub fn from_indices(indices: Vec<u32>) -> Self
pub fn from_indices(indices: Vec<u32>) -> Self
A selection from positions a caller has already worked out, in order.
For a kernel that fills a buffer of its own and counts as it goes, which is how a selection loop is written without a branch in it: every row writes its index at the current length and only a row that is kept moves the length on. Pushing one at a time would put a capacity check and a conversion on a loop whose whole point is that it has neither.
Sourcepub fn from_predicate(len: usize, keep: impl Fn(usize) -> bool) -> Self
pub fn from_predicate(len: usize, keep: impl Fn(usize) -> bool) -> Self
A selection of the positions a predicate accepts.
Sourcepub fn push(&mut self, index: usize)
pub fn push(&mut self, index: usize)
Adds a position to the end.
§Panics
If the index does not fit in a u32. A vector holds 1024 values and a row group holds
122,880, so an index that large is a bug several layers up rather than a large query.
Sourcepub fn get(&self, slot: usize) -> Option<usize>
pub fn get(&self, slot: usize) -> Option<usize>
The position at slot, where slot counts through the survivors.
Sourcepub fn selectivity(&self, len: usize) -> f64
pub fn selectivity(&self, len: usize) -> f64
What fraction of len positions survived.
This is the number the compaction decision is made on, and it is measured rather than assumed, per section 7.1. Zero length reports 1.0, because a filter over nothing has not rejected anything.
Sourcepub fn compose(&self, earlier: &Self) -> Self
pub fn compose(&self, earlier: &Self) -> Self
This selection composed with an earlier one, so that filtering twice does not need the intermediate to be materialized.
self indexes into earlier, and the result indexes into whatever earlier indexed into.
Getting this backwards produces a query that returns the wrong rows rather than an error,
which is why the direction is spelled out here and tested below.
Sourcepub fn without(&self, taken: &Self) -> Self
pub fn without(&self, taken: &Self) -> Self
The positions this selection holds that taken does not.
Both sides have to be in ascending order, which every selection in this engine is: a kernel fills one by walking the rows upward and a composed one keeps that order. So this is one merge over the pair rather than a search per position.
This is what a threaded OR narrows its work with. Each branch is given the rows no branch
before it accepted, and the rows it accepts come out of that set for the branch after.
Sourcepub fn complement(&self, len: usize) -> Self
pub fn complement(&self, len: usize) -> Self
The positions below len that this selection does not hold.
The other half of a threaded OR. What the branches leave behind is the rows none of them
accepted, and the rows the filter keeps are all the others.