Trait memtable_core::Table[][src]

pub trait Table: Sized {
    type Data;
    type Row: List<Item = Self::Data>;
    type Column: List<Item = Self::Data>;
Show methods fn max_row_capacity(&self) -> Capacity;
fn max_column_capacity(&self) -> Capacity;
fn row_cnt(&self) -> usize;
fn col_cnt(&self) -> usize;
fn cell(&self, row: usize, col: usize) -> Option<&Self::Data>;
fn mut_cell(&mut self, row: usize, col: usize) -> Option<&mut Self::Data>;
fn insert_cell(
        &mut self,
        row: usize,
        col: usize,
        value: Self::Data
    ) -> Option<Self::Data>;
fn remove_cell(&mut self, row: usize, col: usize) -> Option<Self::Data>; fn set_preferred_row_cnt(&mut self, cnt: usize) { ... }
fn set_preferred_col_cnt(&mut self, cnt: usize) { ... }
fn len(&self) -> usize { ... }
fn is_empty(&self) -> bool { ... }
fn rows(&self) -> Rows<'_, Self::Data, Self>

Notable traits for Rows<'a, D, T>

impl<'a, D, T: Table<Data = D>> Iterator for Rows<'a, D, T> type Item = Row<'a, D, T>;
{ ... }
fn row(&self, idx: usize) -> Row<'_, Self::Data, Self>

Notable traits for Row<'a, D, T>

impl<'a, D: 'a, T: Table<Data = D>> Iterator for Row<'a, D, T> type Item = &'a D;
{ ... }
fn into_row(self, idx: usize) -> IntoRow<Self::Data, Self>

Notable traits for IntoRow<D, T>

impl<D, T: Table<Data = D>> Iterator for IntoRow<D, T> type Item = D;
{ ... }
fn columns(&self) -> Columns<'_, Self::Data, Self>

Notable traits for Columns<'a, D, T>

impl<'a, D, T: Table<Data = D>> Iterator for Columns<'a, D, T> type Item = Column<'a, D, T>;
{ ... }
fn column(&self, idx: usize) -> Column<'_, Self::Data, Self>

Notable traits for Column<'a, D, T>

impl<'a, D: 'a, T: Table<Data = D>> Iterator for Column<'a, D, T> type Item = &'a D;
{ ... }
fn into_column(self, idx: usize) -> IntoColumn<Self::Data, Self>

Notable traits for IntoColumn<D, T>

impl<D, T: Table<Data = D>> Iterator for IntoColumn<D, T> type Item = D;
{ ... }
fn cells(&self) -> Cells<'_, Self::Data, Self>

Notable traits for Cells<'a, D, T>

impl<'a, D: 'a, T: Table<Data = D>> Iterator for Cells<'a, D, T> type Item = &'a D;
{ ... }
fn into_cells(self) -> IntoCells<Self::Data, Self>

Notable traits for IntoCells<D, T>

impl<D, T: Table<Data = D>> Iterator for IntoCells<D, T> type Item = D;
{ ... }
fn has_cell(&self, row: usize, col: usize) -> bool { ... }
fn insert_row<I: IntoIterator<Item = Self::Data>>(
        &mut self,
        row: usize,
        cells: I
    ) { ... }
fn push_row<I: IntoIterator<Item = Self::Data>>(&mut self, cells: I) { ... }
fn remove_row(&mut self, row: usize) -> Option<Self::Row> { ... }
fn pop_row(&mut self) -> Option<Self::Row> { ... }
fn insert_column<I: IntoIterator<Item = Self::Data>>(
        &mut self,
        col: usize,
        cells: I
    ) { ... }
fn push_column<I: IntoIterator<Item = Self::Data>>(&mut self, cells: I) { ... }
fn remove_column(&mut self, col: usize) -> Option<Self::Column> { ... }
fn pop_column(&mut self) -> Option<Self::Column> { ... }
}
Expand description

Represents an abstract table of data

Associated Types

The type of data stored in individual cells within the table

The type of structure to hold a row of data

The type of structure to hold a column of data

Required methods

Returns the maximum row capacity of the table

Returns the maximum column capacity of the table

Returns the total rows contained in the table

Examples

When empty:

let table = DynamicTable::<usize>::new();
assert_eq!(table.row_cnt(), 0);

When has several rows:

let mut table = DynamicTable::<usize>::new();
table.push_row(vec![1, 2, 3]);
table.push_row(vec![4, 5, 6]);
assert_eq!(table.row_cnt(), 2);

Returns the total columns contained in the table

Examples

When empty:

let table = DynamicTable::<usize>::new();
assert_eq!(table.col_cnt(), 0);

When has several columns:

let mut table = DynamicTable::<usize>::new();
table.push_column(vec![1, 2, 3]);
table.push_column(vec![4, 5, 6]);
assert_eq!(table.col_cnt(), 2);

Returns reference to the cell found at the specified row and column

Examples

When retrieving a cell that doesn’t exist:

let mut table = DynamicTable::new();
table.push_row(vec![1, 2, 3]);
assert!(table.cell(0, 3).is_none());

When retrieving a cell that does exist:

let mut table = DynamicTable::new();
table.push_row(vec![1, 2, 3]);
assert_eq!(table.cell(0, 2), Some(&3));

Returns mut reference to the cell found at the specified row and column

Examples

When retrieving a cell that doesn’t exist:

let mut table = DynamicTable::new();
table.push_row(vec![1, 2, 3]);
assert!(table.mut_cell(0, 3).is_none());

When retrieving a cell that does exist:

let mut table = DynamicTable::new();
table.push_row(vec![1, 2, 3]);

*table.mut_cell(0, 2).unwrap() = 999;
assert_eq!(table.cell(0, 2), Some(&999));

Replaces the given value into the cell of the table at the specified row and column, returning the previous value contained in the cell

Examples

When replacing a cell that doesn’t exist:

let mut table = DynamicTable::new();
table.push_row(vec![1, 2, 3]);

assert!(table.insert_cell(0, 3, 999).is_none());
assert_eq!(table.cell(0, 3), Some(&999));

When replacing a cell that does exist:

let mut table = DynamicTable::new();
table.push_row(vec![1, 2, 3]);

assert_eq!(table.insert_cell(0, 2, 999), Some(3));
assert_eq!(table.cell(0, 2), Some(&999));

Removes the given value from the cell at the specified position, but does not shift any other cell to fill in the gap

Does not attempt to adjust the capacity within the table

Examples

let mut table = DynamicTable::new();
table.push_row(vec![1, 2, 3]);

assert_eq!(table.remove_cell(0, 0), Some(1));
assert!(table.remove_cell(0, 0).is_none());

Provided methods

Sets the preferred capacity of the table when it comes to total rows

This is a preference, not an absolute, and is up to each table to implement if desired; otherwise, this does nothing by default

Sets the preferred capacity of the table when it comes to total columns

This is a preference, not an absolute, and is up to each table to implement if desired; otherwise, this does nothing by default

Returns the total cells (rows * columns) contained in the table

Examples

When empty:

let table = DynamicTable::<usize>::new();
assert_eq!(table.len(), 0);

When has several rows & columns:

let mut table = DynamicTable::<usize>::new();
table.push_row(vec![1, 2, 3]);
table.push_row(vec![4, 5, 6]);
assert_eq!(table.len(), 6);

Returns true if the total cells (rows * columns) contained in the table is zero

Examples

When empty:

let table = DynamicTable::<usize>::new();
assert!(table.is_empty());

When has several rows & columns:

let mut table = DynamicTable::<usize>::new();
table.push_row(vec![1, 2, 3]);
table.push_row(vec![4, 5, 6]);
assert!(!table.is_empty());

Returns an iterator of refs through all rows in the table

Examples

When empty:

let table = DynamicTable::<usize>::new();
assert_eq!(table.rows().len(), 0);

When has several rows:

let mut table = DynamicTable::<usize>::new();
table.push_row(vec![1, 2, 3]);
table.push_row(vec![4, 5, 6]);

let mut rows = table.rows();
assert_eq!(rows.next().unwrap().copied().collect::<Vec<usize>>(), vec![1, 2, 3]);
assert_eq!(rows.next().unwrap().copied().collect::<Vec<usize>>(), vec![4, 5, 6]);
assert!(rows.next().is_none());

Returns an iterator of refs through a specific row in the table

Examples

When empty:

let table = DynamicTable::<usize>::new();
assert_eq!(table.row(0).len(), 0);

When has several rows:

let mut table = DynamicTable::<usize>::new();
table.push_row(vec![1, 2, 3]);
table.push_row(vec![4, 5, 6]);

let mut cells = table.row(0);
assert_eq!(cells.next().copied(), Some(1));
assert_eq!(cells.next().copied(), Some(2));
assert_eq!(cells.next().copied(), Some(3));
assert_eq!(cells.next(), None);

Consumes the table and returns an iterator through a specific row in the table

Examples

When empty:

let table = DynamicTable::<usize>::new();
assert_eq!(table.into_row(0).len(), 0);

When has several rows:

let mut table = DynamicTable::<usize>::new();
table.push_row(vec![1, 2, 3]);
table.push_row(vec![4, 5, 6]);

let mut cells = table.into_row(0);
assert_eq!(cells.next(), Some(1));
assert_eq!(cells.next(), Some(2));
assert_eq!(cells.next(), Some(3));
assert_eq!(cells.next(), None);

Returns an iterator of refs through all columns in the table

Examples

When empty:

let table = DynamicTable::<usize>::new();
assert_eq!(table.columns().len(), 0);

When has several columns:

let mut table = DynamicTable::<usize>::new();
table.push_column(vec![1, 2, 3]);
table.push_column(vec![4, 5, 6]);

let mut columns = table.columns();
assert_eq!(columns.next().unwrap().copied().collect::<Vec<usize>>(), vec![1, 2, 3]);
assert_eq!(columns.next().unwrap().copied().collect::<Vec<usize>>(), vec![4, 5, 6]);
assert!(columns.next().is_none());

Returns an iterator of refs through a specific column in the table

Examples

When empty:

let table = DynamicTable::<usize>::new();
assert_eq!(table.column(0).len(), 0);

When has several columns:

let mut table = DynamicTable::<usize>::new();
table.push_column(vec![1, 2, 3]);
table.push_column(vec![4, 5, 6]);

let mut cells = table.column(0);
assert_eq!(cells.next().copied(), Some(1));
assert_eq!(cells.next().copied(), Some(2));
assert_eq!(cells.next().copied(), Some(3));
assert_eq!(cells.next(), None);

Consumes the table and returns an iterator through a specific column in the table

Examples

When empty:

let table = DynamicTable::<usize>::new();
assert_eq!(table.into_column(0).len(), 0);

When has several columns:

let mut table = DynamicTable::<usize>::new();
table.push_column(vec![1, 2, 3]);
table.push_column(vec![4, 5, 6]);

let mut cells = table.into_column(0);
assert_eq!(cells.next(), Some(1));
assert_eq!(cells.next(), Some(2));
assert_eq!(cells.next(), Some(3));
assert_eq!(cells.next(), None);

Returns an iterator of refs through all cells in the table, starting from the first row, iterating through all cells from beginning to end, and then moving on to the next row

Examples

When empty:

let table = DynamicTable::<usize>::new();
assert_eq!(table.cells().len(), 0);

When has several rows & columns:

let mut table = DynamicTable::<usize>::new();
table.push_row(vec![1, 2, 3]);
table.push_row(vec![4, 5, 6]);

let mut cells = table.cells();
assert_eq!(cells.next(), Some(&1));
assert_eq!(cells.next(), Some(&2));
assert_eq!(cells.next(), Some(&3));
assert_eq!(cells.next(), Some(&4));
assert_eq!(cells.next(), Some(&5));
assert_eq!(cells.next(), Some(&6));
assert_eq!(cells.next(), None);

Consumes the table and returns an iterator through all cells in the table, starting from the first row, iterating through all cells from beginning to end, and then moving on to the next row

Examples

When empty:

let table = DynamicTable::<usize>::new();
assert_eq!(table.into_cells().len(), 0);

When has several rows & columns:

let mut table = DynamicTable::<usize>::new();
table.push_row(vec![1, 2, 3]);
table.push_row(vec![4, 5, 6]);

let mut cells = table.into_cells();
assert_eq!(cells.next(), Some(1));
assert_eq!(cells.next(), Some(2));
assert_eq!(cells.next(), Some(3));
assert_eq!(cells.next(), Some(4));
assert_eq!(cells.next(), Some(5));
assert_eq!(cells.next(), Some(6));
assert_eq!(cells.next(), None);

Returns whether or not a cell exists at the specified row & column. Note that this is not the same as whether or not the table’s current row & column range would include a cell at that position! Rather, this is reporting if a cell actually exists

Examples

When has checking for a cell that doesn’t exist:

let mut table = DynamicTable::new();
table.push_row(vec![1, 2, 3]);
assert!(!table.has_cell(0, 3));

When has checking for a cell that does exist:

let mut table = DynamicTable::new();
table.push_row(vec![1, 2, 3]);
assert!(table.has_cell(0, 2));

Inserts a new row into the table at the given position, shifting down all rows after it

Examples

let mut table = DynamicTable::new();
table.push_row(vec![1, 2, 3]);
table.push_row(vec![4, 5, 6]);

table.insert_row(0, vec![7, 8, 9]);

let mut row = table.row(0);
assert_eq!(row.next(), Some(&7));
assert_eq!(row.next(), Some(&8));
assert_eq!(row.next(), Some(&9));
assert!(row.next().is_none());

let mut row = table.row(1);
assert_eq!(row.next(), Some(&1));
assert_eq!(row.next(), Some(&2));
assert_eq!(row.next(), Some(&3));
assert!(row.next().is_none());

let mut row = table.row(2);
assert_eq!(row.next(), Some(&4));
assert_eq!(row.next(), Some(&5));
assert_eq!(row.next(), Some(&6));
assert!(row.next().is_none());

Pushes a row to the end of the table

Examples

let mut table = DynamicTable::new();
table.push_row(vec![1, 2, 3]);
table.push_row(vec![4, 5, 6]);

let mut row = table.row(0);
assert_eq!(row.next(), Some(&1));
assert_eq!(row.next(), Some(&2));
assert_eq!(row.next(), Some(&3));
assert!(row.next().is_none());

let mut row = table.row(1);
assert_eq!(row.next(), Some(&4));
assert_eq!(row.next(), Some(&5));
assert_eq!(row.next(), Some(&6));
assert!(row.next().is_none());

Removes the row at the specified position, shifting up all rows after it

If the row does not exist, then an empty row will be returned

Examples

Removing from the front:

let mut table = DynamicTable::new();
table.push_row(vec![1, 2, 3]);
table.push_row(vec![4, 5, 6]);

assert_eq!(table.remove_row(0), Some(DynamicList::from([1, 2, 3])));
assert_eq!(table.remove_row(0), Some(DynamicList::from([4, 5, 6])));
assert_eq!(table.remove_row(0), None);

Removing from the back:

let mut table = DynamicTable::new();
table.push_row(vec![1, 2, 3]);
table.push_row(vec![4, 5, 6]);

assert_eq!(table.remove_row(1), Some(DynamicList::from([4, 5, 6])));
assert_eq!(table.remove_row(1), None);
assert_eq!(table.remove_row(0), Some(DynamicList::from([1, 2, 3])));
assert_eq!(table.remove_row(0), None);

Pops a row off the end of the table

Examples

let mut table = DynamicTable::new();
table.push_row(vec![1, 2, 3]);
table.push_row(vec![4, 5, 6]);

assert_eq!(table.pop_row(), Some(DynamicList::from([4, 5, 6])));
assert_eq!(table.pop_row(), Some(DynamicList::from([1, 2, 3])));
assert_eq!(table.pop_row(), None);

Inserts a new column into the table at the given position, shifting right all columns after it

Examples

let mut table = DynamicTable::new();
table.push_column(vec![1, 2, 3]);
table.push_column(vec![4, 5, 6]);

table.insert_column(0, vec![7, 8, 9]);

let mut column = table.column(0);
assert_eq!(column.next(), Some(&7));
assert_eq!(column.next(), Some(&8));
assert_eq!(column.next(), Some(&9));
assert!(column.next().is_none());

let mut column = table.column(1);
assert_eq!(column.next(), Some(&1));
assert_eq!(column.next(), Some(&2));
assert_eq!(column.next(), Some(&3));
assert!(column.next().is_none());

let mut column = table.column(2);
assert_eq!(column.next(), Some(&4));
assert_eq!(column.next(), Some(&5));
assert_eq!(column.next(), Some(&6));
assert!(column.next().is_none());

Pushes a column to the end of the table

Examples

let mut table = DynamicTable::new();
table.push_column(vec![1, 2, 3]);
table.push_column(vec![4, 5, 6]);

let mut column = table.column(0);
assert_eq!(column.next(), Some(&1));
assert_eq!(column.next(), Some(&2));
assert_eq!(column.next(), Some(&3));
assert!(column.next().is_none());

let mut column = table.column(1);
assert_eq!(column.next(), Some(&4));
assert_eq!(column.next(), Some(&5));
assert_eq!(column.next(), Some(&6));
assert!(column.next().is_none());

Removes the column at the specified position, shifting left all columns after it

If the column does not exist, then an empty column will be returned

Examples

Removing from the front:

let mut table = DynamicTable::new();
table.push_column(vec![1, 2, 3]);
table.push_column(vec![4, 5, 6]);

assert_eq!(table.remove_column(0), Some(DynamicList::from([1, 2, 3])));
assert_eq!(table.remove_column(0), Some(DynamicList::from([4, 5, 6])));
assert_eq!(table.remove_column(0), None);

Removing from the the back:

let mut table = DynamicTable::new();
table.push_column(vec![1, 2, 3]);
table.push_column(vec![4, 5, 6]);

assert_eq!(table.remove_column(1), Some(DynamicList::from([4, 5, 6])));
assert_eq!(table.remove_column(1), None);
assert_eq!(table.remove_column(0), Some(DynamicList::from([1, 2, 3])));
assert_eq!(table.remove_column(0), None);

Pops a column off the end of the table

Examples

let mut table = DynamicTable::new();
table.push_column(vec![1, 2, 3]);
table.push_column(vec![4, 5, 6]);

assert_eq!(table.pop_column(), Some(DynamicList::from([4, 5, 6])));
assert_eq!(table.pop_column(), Some(DynamicList::from([1, 2, 3])));
assert_eq!(table.pop_column(), None);

Implementors