pub struct Amalgamator<T: Amalgamate, S = RandomState>(/* private fields */);Expand description
A set/map like data structure that allows you to combine members of the set/map together based on some criteria.
Implementations§
Source§impl<T> Amalgamator<T>where
T: Amalgamate,
impl<T> Amalgamator<T>where
T: Amalgamate,
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new Amalgamator with the given capacity.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of elements the map can hold without reallocating.
Sourcepub fn add(&mut self, item: T)
pub fn add(&mut self, item: T)
Adds an element to the Amalgamator.
If an element with the same key already exists in the Amalgamator, the two elements will be combined.
This will be done by calling Amalgamate::amalgamate on the existing element with the new element as
an argument.
Sourcepub fn get_by_key<Q>(&self, key: &Q) -> Option<&T>
pub fn get_by_key<Q>(&self, key: &Q) -> Option<&T>
Returns a reference to the element with the given key.
Sourcepub fn get_by_key_mut<Q>(&mut self, key: &Q) -> Option<&mut T>
pub fn get_by_key_mut<Q>(&mut self, key: &Q) -> Option<&mut T>
Returns a mutable reference to the element with the given key.
Sourcepub fn remove_by_key<Q>(&mut self, key: &Q) -> Option<T>
pub fn remove_by_key<Q>(&mut self, key: &Q) -> Option<T>
Removes the element with the given key from the Amalgamator and returns it.
Sourcepub fn get_key_value<Q>(&self, key: &Q) -> Option<(&T::Key, &T)>
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&T::Key, &T)>
Returns the key-value pair corresponding to the supplied key.
Sourcepub fn remove(&mut self, item: &T) -> Option<T>
pub fn remove(&mut self, item: &T) -> Option<T>
Removes the element from the Amalgamator and returns it.
Sourcepub fn contains(&self, item: &T) -> bool
pub fn contains(&self, item: &T) -> bool
Returns true if the Amalgamator contains the given element.
Keep in mind that this is checking for something that has the same key, not the same value.
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Returns true if the Amalgamator contains an element with the given key.
Keep in mind that this is checking for something that has the same key, not the same value.
Sourcepub fn keys(&self) -> impl Iterator<Item = &T::Key>
pub fn keys(&self) -> impl Iterator<Item = &T::Key>
Returns an iterator over the keys of the Amalgamator.
Sourcepub fn values(&self) -> impl Iterator<Item = &T>
pub fn values(&self) -> impl Iterator<Item = &T>
Returns an iterator over the values of the Amalgamator.
Sourcepub fn values_mut(&mut self) -> impl Iterator<Item = &mut T>
pub fn values_mut(&mut self) -> impl Iterator<Item = &mut T>
Returns an iterator over the mutable values of the Amalgamator.
Sourcepub fn into_values(self) -> impl Iterator<Item = T>
pub fn into_values(self) -> impl Iterator<Item = T>
Returns an iterator over the values of the Amalgamator.
Sourcepub fn into_keys(self) -> impl Iterator<Item = T::Key>
pub fn into_keys(self) -> impl Iterator<Item = T::Key>
Returns an iterator over the keys of the Amalgamator.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&T::Key, &T)>
pub fn iter(&self) -> impl Iterator<Item = (&T::Key, &T)>
Returns an iterator over the elements of the Amalgamator.
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = (&T::Key, &mut T)>
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&T::Key, &mut T)>
Returns an iterator over the mutable elements of the Amalgamator.
Source§impl<T, S> Amalgamator<T, S>where
T: Amalgamate,
S: BuildHasher,
impl<T, S> Amalgamator<T, S>where
T: Amalgamate,
S: BuildHasher,
Sourcepub fn with_hasher(hash_builder: S) -> Self
pub fn with_hasher(hash_builder: S) -> Self
Creates a new Amalgamator with the given hasher.
Sourcepub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self
pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self
Creates a new Amalgamator with the given hasher and capacity.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional more elements to be inserted in the Amalgamator.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the Amalgamator as much as possible.
Trait Implementations§
Source§impl<T: Clone + Amalgamate, S: Clone> Clone for Amalgamator<T, S>
impl<T: Clone + Amalgamate, S: Clone> Clone for Amalgamator<T, S>
Source§fn clone(&self) -> Amalgamator<T, S>
fn clone(&self) -> Amalgamator<T, S>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug + Amalgamate, S: Debug> Debug for Amalgamator<T, S>
impl<T: Debug + Amalgamate, S: Debug> Debug for Amalgamator<T, S>
Source§impl<T> Default for Amalgamator<T>where
T: Amalgamate,
impl<T> Default for Amalgamator<T>where
T: Amalgamate,
Source§impl<T> Extend<T> for Amalgamator<T>where
T: Amalgamate,
impl<T> Extend<T> for Amalgamator<T>where
T: Amalgamate,
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)