Struct shortcut::Store
[−]
[src]
pub struct Store<T: PartialOrd + Clone> { // some fields omitted }
A Store
is the main storage unit in shortcut. It keeps track of all the rows of data, as well
as what indices are available. You will generally be accessing the Store
either through the
find
method (which lets you find rows that match a certain condition), or through the
insert
method, which lets you add another row.
Note that the type used for the rows needs to be Clone
. This is because the value is also
given to the index, which (currently) take a full value, not just a borrow. This might change
down the line, but it's tricky to get the lifetimes to work out, because the indices would then
be scoped by the lifetime of the Store
.
Methods
impl<T: PartialOrd + Clone> Store<T>
[src]
fn new(cols: usize) -> Store<T>
Allocate a new Store
with the given number of columns. The column count is checked in
insert
at runtime (bleh).
fn with_capacity(cols: usize, rows: usize) -> Store<T>
Allocate a new Store
with the given number of columns, and with room for the given number
of rows. If you know roughly how many rows will be inserted, this will speed up insertion a
fair amount, as it avoids needing to re-allocate the underlying Vec
whenever it needs to
grow. As with new
, the column count is checked in insert
at runtime.
fn find<'a>(&'a self, conds: &'a [Condition<T>]) -> Box<Iterator<Item=&'a [T]> + 'a>
Returns an iterator that yields all rows matching all the given Condition
s.
This method will automatically determine what index to use to satisfy this query. It
currently uses a fairly simple heuristic: it picks the index that: a) is over one of
columns being filtered on; b) supports the operation for that filter; and c) has the lowest
expected number of rows for a single value. This latter metric is generally the total
number of rows divided by the number of entries in the index. See EqualityIndex::estimate
for details.
fn insert(&mut self, row: Vec<T>)
Insert a new data row into the Store
. The row must have the same number of columns as
specified when the Store
was created. If it does not, the code will panic with an
assertion failure.
Inserting a row has similar complexity to Vec::push
, and may need to re-allocate the
backing memory for the Store
. The insertion also updates all maintained indices, which
may also re-allocate.
fn index<I: Into<Index<T>>>(&mut self, column: usize, indexer: I)
Add an index on the given colum using the given indexer. The indexer must, at the very
least, implement EqualityIndex
. It may also implement other, more sophisticated,
indexing strategies outlined in Index
.
When an index is added, it is immediately fed all rows in the current dataset. Thus, adding
an index to a Store
with many rows can be fairly costly. Keep this in mind!