Struct shortcut::Store[][src]

pub struct Store<T, C = Vec<T>> { /* 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.

Implementations

impl<T, R> Store<T, R> where
    T: Ord + Clone,
    R: Row<T>, 
[src]

pub fn new(cols: usize) -> Store<T, R>[src]

Allocate a new Store with the given number of columns. The column count is checked in insert at runtime (bleh).

pub fn find<'c, 's: 'c>(
    &'s self,
    conds: &'c [Condition<'c, T>]
) -> Box<dyn Iterator<Item = &'s R> + 'c>
[src]

Returns an iterator that yields all rows matching all the given Conditions.

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.

pub fn delete(&mut self, conds: &[Condition<'_, T>])[src]

Delete all rows that match the given conditions.

pub fn delete_filter<F>(&mut self, conds: &[Condition<'_, T>], f: F) where
    F: FnMut(&R) -> bool
[src]

Delete all rows that match the given conditions and where the given filter function returns true.

This requires that R implements IntoIterator, and that the columns are yielded in column order.

pub fn insert(&mut self, row: R)[src]

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.

pub fn index<I: Into<Index<T>>>(&mut self, column: usize, indexer: I)[src]

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!

Auto Trait Implementations

impl<T, C = Vec<T, Global>> !RefUnwindSafe for Store<T, C>

impl<T, C> Send for Store<T, C> where
    C: Send

impl<T, C> Sync for Store<T, C> where
    C: Sync

impl<T, C> Unpin for Store<T, C>

impl<T, C = Vec<T, Global>> !UnwindSafe for Store<T, C>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.