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>

source

pub fn iter(&self) -> HashTableBorrowedIter<'_, K, V>

Row-wise iterator that borrows the table

source

pub fn into_iter_columns(self) -> HashTableOwnedIntoIterColumn<K, V>

Column-wise iterator that takes ownership of the keys and values

source

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>

source

pub fn columns_len(&self) -> usize

Returns the number of columns in this table.

source

pub fn rows_len(&self) -> usize

Returns the number of rows in this table.

source

pub fn with_capacity(columns: usize, rows: usize) -> Self

Create new HashTable with specified amoutn of reserved capacity.

source

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.

source

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.

source

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>
where K: Hash + Eq,

source

pub fn with_columns(columns: impl IntoIterator<Item = K>) -> Self

Create a HashTable from iterator of column keys.

source

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.

source

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.

source

pub fn get<Q>(&self, column: &Q, row: usize) -> Option<&V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Get an element from the table.

Will return None of the column does not exist in teh table or row is out of range.

source

pub fn get_mut<Q>(&mut self, column: &Q, row: usize) -> Option<&mut V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

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.

source

pub fn get_column<'t, 'k, Q>( &'t self, column: &'k Q ) -> Option<HashTableColumnBorrowed<'t, 'k, Q, V>>
where K: Borrow<Q>, Q: Hash + Eq,

Get an immutable access to a table column.

Will return None if the column does not exist in the table.

source

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.

source

pub fn add_row_with<F>(&mut self, row_generator: F)
where F: FnMut(&K) -> V,

Add a row to the table using a generator function that returns the value from the column key.

source

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.

source

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.

source

pub fn remove_column<Q>( &mut self, column: &Q ) -> Option<HashTableColumnOwned<K, V>>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

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.

source

pub fn from_column_iter<I>(iter: I) -> Self
where I: IntoIterator<Item = HashTableColumnOwned<K, V>>,

Construct HashTable from iterator of columns

Trait Implementations§

source§

impl<K: Clone, V: Clone> Clone for HashTable<K, V>

source§

fn clone(&self) -> HashTable<K, V>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<K: Debug, V: Debug> Debug for HashTable<K, V>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<K: Default, V: Default> Default for HashTable<K, V>

source§

fn default() -> HashTable<K, V>

Returns the “default value” for a type. Read more
source§

impl<K, V> From<HashTableFromColumns<K, V>> for HashTable<K, V>

source§

fn from(value: HashTableFromColumns<K, V>) -> Self

Converts to this type from the input type.
source§

impl<K, V, R> FromIterator<R> for HashTable<K, V>
where K: Hash + Eq, R: IntoIterator<Item = (K, V)>,

source§

fn from_iter<T: IntoIterator<Item = R>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl<K, V> IntoIterator for HashTable<K, V>
where K: Clone + Hash + Eq,

source§

fn into_iter(self) -> Self::IntoIter

Row-wise iterator that takes ownership of both keys and values, cloning the keys each time and allocating a new hashmap.

§

type Item = HashMap<K, V>

The type of the elements being iterated over.
§

type IntoIter = HashTableIntoIter<K, V>

Which kind of iterator are we turning this into?

Auto Trait Implementations§

§

impl<K, V> RefUnwindSafe for HashTable<K, V>

§

impl<K, V> Send for HashTable<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for HashTable<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for HashTable<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnwindSafe for HashTable<K, V>
where K: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.