Struct shortcut::Store
[−]
[src]
pub struct Store<T: PartialOrd + Clone> { /* 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 find<'s: 'c, 'c>(&'s self,
conds: &'c [Condition<T>])
-> Box<Iterator<Item=&'s [T]> + 'c>
conds: &'c [Condition<T>])
-> Box<Iterator<Item=&'s [T]> + 'c>
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.
The lifetime bounds here deserve some explanation. Previously, this was simply 'a
for
everything, but this means that the items returned from the iterator were bound by the
lifetime of the conditions. This is clearly not necessary. It also meant that you couldn't
.collect()
the results and continue referring to them after the conditions have gone out
of scope.
fn delete(&mut self, conds: &[Condition<T>])
Delete all rows that match the given conditions.
fn delete_filter<F: FnMut(&[T]) -> bool>(&mut self,
conds: &[Condition<T>],
f: F)
conds: &[Condition<T>],
f: F)
Delete all rows that match the given conditions and where the given filter function returns true.
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 BTreeMap::insert
, 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!