Struct hash_table_datastruct::table::HashTable
source · pub struct HashTable<K, V> { /* private fields */ }Expand description
This data structure represents a 2-dimensional grid of values. Each element is indexed by a hashable key and a row index. It’s also possible to access a whole row or column of the table.
Implementations§
source§impl<K, V> HashTable<K, V>
impl<K, V> HashTable<K, V>
sourcepub fn iter(&self) -> HashTableBorrowedIter<'_, K, V> ⓘ
pub fn iter(&self) -> HashTableBorrowedIter<'_, K, V> ⓘ
Row-wise iterator that borrows the table
sourcepub fn into_iter_columns(self) -> HashTableOwnedIntoIterColumn<K, V> ⓘ
pub fn into_iter_columns(self) -> HashTableOwnedIntoIterColumn<K, V> ⓘ
Column-wise iterator that takes ownership of the keys and values
sourcepub fn iter_columns(&self) -> HashTableBorrowedIterColumn<'_, K, V> ⓘ
pub fn iter_columns(&self) -> HashTableBorrowedIterColumn<'_, K, V> ⓘ
Column-wise iterator that borrows the values from the table
source§impl<K, V> HashTable<K, V>
impl<K, V> HashTable<K, V>
sourcepub fn columns_len(&self) -> usize
pub fn columns_len(&self) -> usize
Returns the number of columns in this table.
sourcepub fn with_capacity(columns: usize, rows: usize) -> Self
pub fn with_capacity(columns: usize, rows: usize) -> Self
Create new HashTable with specified amoutn of reserved capacity.
sourcepub fn get_row(&self, row: usize) -> Option<HashTableRowBorrowed<'_, K, V>>
pub fn get_row(&self, row: usize) -> Option<HashTableRowBorrowed<'_, K, V>>
Get a row of the table.
Returns None if row is bigger than or equal to the number of rows.
sourcepub fn get_row_mut(
&mut self,
row: usize
) -> Option<HashTableMutableBorrowedRow<'_, K, V>>
pub fn get_row_mut( &mut self, row: usize ) -> Option<HashTableMutableBorrowedRow<'_, K, V>>
Get row with mutable access.
Returns None if row is bigger than or equal to the number of row.
sourcepub fn remove_row(
&mut self,
row: usize
) -> Option<HashTableRowValueOwned<'_, K, V>>
pub fn remove_row( &mut self, row: usize ) -> Option<HashTableRowValueOwned<'_, K, V>>
Remove a row and take ownership of its values.
This still borrows the hashtable immutably to allow getting the values by a key. Keys can be converted to an owned variant, usually by cloning them.
source§impl<K, V> HashTable<K, V>
impl<K, V> HashTable<K, V>
sourcepub fn with_columns(columns: impl IntoIterator<Item = K>) -> Self
pub fn with_columns(columns: impl IntoIterator<Item = K>) -> Self
Create a HashTable from iterator of column keys.
sourcepub fn with_columns_and_capacity(
columns: impl IntoIterator<Item = K>,
rows: usize
) -> Self
pub fn with_columns_and_capacity( columns: impl IntoIterator<Item = K>, rows: usize ) -> Self
Create a HashTable from iterator of column keys and with allocated capacity for at
least the specified amount of rows.
sourcepub fn remove_row_hashmap(&mut self, row: usize) -> Option<HashMap<&K, V>>
pub fn remove_row_hashmap(&mut self, row: usize) -> Option<HashMap<&K, V>>
Remove row from the hashtable, taking ownership of teh values. Returns a HashMap
The difference from Self::remove_row is that this only allocates a hashmap that
references teh keys instead of allocating valeus and taking a reference to a hashmap of
indices used internally.
sourcepub fn get<Q>(&self, column: &Q, row: usize) -> Option<&V>
pub fn get<Q>(&self, column: &Q, row: usize) -> Option<&V>
Get an element from the table.
Will return None of the column does not exist in teh table or row is out of range.
sourcepub fn get_mut<Q>(&mut self, column: &Q, row: usize) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, column: &Q, row: usize) -> Option<&mut V>
Get an element from the table with mutable access.
Will return None of the column does not exist in the table or row is out of range.
sourcepub fn get_column<'t, 'k, Q>(
&'t self,
column: &'k Q
) -> Option<HashTableColumnBorrowed<'t, 'k, Q, V>>
pub fn get_column<'t, 'k, Q>( &'t self, column: &'k Q ) -> Option<HashTableColumnBorrowed<'t, 'k, Q, V>>
Get an immutable access to a table column.
Will return None if the column does not exist in the table.
sourcepub fn add_row<I>(&mut self, row: I)where
I: IntoIterator<Item = (K, V)>,
pub fn add_row<I>(&mut self, row: I)where
I: IntoIterator<Item = (K, V)>,
Add a row to the table from an iterator of key-value pairs.
sourcepub fn add_row_with<F>(&mut self, row_generator: F)
pub fn add_row_with<F>(&mut self, row_generator: F)
Add a row to the table using a generator function that returns the value from the column key.
sourcepub fn add_column<I>(&mut self, column: K, values: I)where
I: IntoIterator<Item = V>,
pub fn add_column<I>(&mut self, column: K, values: I)where
I: IntoIterator<Item = V>,
Add a column with values provided through an iterator.
sourcepub fn add_column_with<F>(&mut self, column: K, values: F)where
F: FnMut(HashTableRowBorrowed<'_, K, V>) -> V,
pub fn add_column_with<F>(&mut self, column: K, values: F)where
F: FnMut(HashTableRowBorrowed<'_, K, V>) -> V,
Add a column using a generator function that returns a value based on the values of the row.
sourcepub fn remove_column<Q>(
&mut self,
column: &Q
) -> Option<HashTableColumnOwned<K, V>>
pub fn remove_column<Q>( &mut self, column: &Q ) -> Option<HashTableColumnOwned<K, V>>
Remove a column from the table and take ownership of the key and values.
Will return None if the column does not exist in the table.
sourcepub fn from_column_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = HashTableColumnOwned<K, V>>,
pub fn from_column_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = HashTableColumnOwned<K, V>>,
Construct HashTable from iterator of columns