Amalgamator

Struct Amalgamator 

Source
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,

Source

pub fn new() -> Self

Creates a new Amalgamator with an empty set/map.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new Amalgamator with the given capacity.

Source

pub fn capacity(&self) -> usize

Returns the number of elements the map can hold without reallocating.

Source

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.

Source

pub fn get_by_key<Q>(&self, key: &Q) -> Option<&T>
where T::Key: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns a reference to the element with the given key.

Source

pub fn get_by_key_mut<Q>(&mut self, key: &Q) -> Option<&mut T>
where T::Key: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns a mutable reference to the element with the given key.

Source

pub fn remove_by_key<Q>(&mut self, key: &Q) -> Option<T>
where T::Key: Borrow<Q>, Q: Hash + Eq + ?Sized,

Removes the element with the given key from the Amalgamator and returns it.

Source

pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&T::Key, &T)>
where T::Key: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns the key-value pair corresponding to the supplied key.

Source

pub fn remove(&mut self, item: &T) -> Option<T>

Removes the element from the Amalgamator and returns it.

Source

pub fn len(&self) -> usize

Returns the number of elements in the Amalgamator.

Source

pub fn is_empty(&self) -> bool

Returns true if the Amalgamator is empty.

Source

pub fn clear(&mut self)

Removes all elements from the Amalgamator.

Source

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.

Source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where T::Key: Borrow<Q>, Q: Hash + Eq + ?Sized,

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.

Source

pub fn keys(&self) -> impl Iterator<Item = &T::Key>

Returns an iterator over the keys of the Amalgamator.

Source

pub fn values(&self) -> impl Iterator<Item = &T>

Returns an iterator over the values of the Amalgamator.

Source

pub fn values_mut(&mut self) -> impl Iterator<Item = &mut T>

Returns an iterator over the mutable values of the Amalgamator.

Source

pub fn into_values(self) -> impl Iterator<Item = T>

Returns an iterator over the values of the Amalgamator.

Source

pub fn into_keys(self) -> impl Iterator<Item = T::Key>

Returns an iterator over the keys of the Amalgamator.

Source

pub fn iter(&self) -> impl Iterator<Item = (&T::Key, &T)>

Returns an iterator over the elements of the Amalgamator.

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = (&T::Key, &mut T)>

Returns an iterator over the mutable elements of the Amalgamator.

Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&mut T) -> bool,

Retains only the elements that satisfy the predicate.

Source

pub fn drain(&mut self) -> impl Iterator<Item = T> + '_

Removes all elements from the Amalgamator and returns them in an iterator.

Source§

impl<T, S> Amalgamator<T, S>
where T: Amalgamate, S: BuildHasher,

Source

pub fn with_hasher(hash_builder: S) -> Self

Creates a new Amalgamator with the given hasher.

Source

pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self

Creates a new Amalgamator with the given hasher and capacity.

Source

pub fn hasher(&self) -> &S

Returns a reference to the hasher used by the Amalgamator.

Source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more elements to be inserted in the Amalgamator.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the Amalgamator as much as possible.

Source

pub fn shrink_to(&mut self, min_capacity: usize)

Shrinks the capacity of the Amalgamator to a minimum.

Trait Implementations§

Source§

impl<T: Clone + Amalgamate, S: Clone> Clone for Amalgamator<T, S>
where T::Key: Clone,

Source§

fn clone(&self) -> Amalgamator<T, S>

Returns a duplicate 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<T: Debug + Amalgamate, S: Debug> Debug for Amalgamator<T, S>
where T::Key: Debug,

Source§

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

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

impl<T> Default for Amalgamator<T>
where T: Amalgamate,

Source§

fn default() -> Self

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

impl<T> Extend<T> for Amalgamator<T>
where T: Amalgamate,

Source§

fn extend<I>(&mut self, iter: I)
where I: IntoIterator<Item = T>,

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<V, const N: usize> From<[V; N]> for Amalgamator<V>
where V: Amalgamate,

Source§

fn from(array: [V; N]) -> Self

Converts to this type from the input type.
Source§

impl<T> FromIterator<T> for Amalgamator<T>
where T: Amalgamate,

Source§

fn from_iter<I>(iter: I) -> Self
where I: IntoIterator<Item = T>,

Creates a value from an iterator. Read more
Source§

impl<Q, T> Index<&Q> for Amalgamator<T>
where T: Amalgamate, T::Key: Borrow<Q>, Q: Hash + Eq + ?Sized,

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, key: &Q) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<Q, T> IndexMut<&Q> for Amalgamator<T>
where T: Amalgamate, T::Key: Borrow<Q>, Q: Hash + Eq + ?Sized,

Source§

fn index_mut(&mut self, key: &Q) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, T> IntoIterator for &'a Amalgamator<T>
where T: Amalgamate,

Source§

type Item = (&'a <T as Amalgamate>::Key, &'a T)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, <T as Amalgamate>::Key, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T> IntoIterator for &'a mut Amalgamator<T>
where T: Amalgamate,

Source§

type Item = (&'a <T as Amalgamate>::Key, &'a mut T)

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, <T as Amalgamate>::Key, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> IntoIterator for Amalgamator<T>
where T: Amalgamate,

Source§

type Item = (<T as Amalgamate>::Key, T)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<T as Amalgamate>::Key, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> PartialEq for Amalgamator<T>
where T: Amalgamate + PartialEq,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Eq for Amalgamator<T>
where T: Amalgamate + Eq,

Auto Trait Implementations§

§

impl<T, S> Freeze for Amalgamator<T, S>
where S: Freeze,

§

impl<T, S> RefUnwindSafe for Amalgamator<T, S>

§

impl<T, S> Send for Amalgamator<T, S>
where S: Send, <T as Amalgamate>::Key: Send, T: Send,

§

impl<T, S> Sync for Amalgamator<T, S>
where S: Sync, <T as Amalgamate>::Key: Sync, T: Sync,

§

impl<T, S> Unpin for Amalgamator<T, S>
where S: Unpin, <T as Amalgamate>::Key: Unpin, T: Unpin,

§

impl<T, S> UnwindSafe for Amalgamator<T, S>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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>,

Source§

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>,

Source§

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.