pub struct SupersetMap<K, V> { /* private fields */ }
Expand description

A minimal collection of (K, V)s. Internally it is based on a BTreeMap. When a (K, V) is SupersetMap::inserted, it won’t actually be inserted unless there isn’t a K already in the map that is a superset of it. In such event, all Ks that are subsets of the to-be-inserted K are removed before inserting the K. Note this can have quite good performance due to the fact that a single search is necessary to detect if insertion should occur; furthermore since all subsets occur immediately before where the key will be inserted, a simple linear scan is sufficient to remove subsets avoiding the need to search the entire map.

Implementations§

source§

impl<K, V> SupersetMap<K, V>

source

pub fn clear(&mut self)

source

pub fn into_keys(self) -> IntoKeys<K, V>

source

pub fn into_values(self) -> IntoValues<K, V>

source

pub fn is_empty(&self) -> bool

source

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

source

pub fn iter_mut(&mut self) -> IterMut<'_, K, V>

source

pub fn keys(&self) -> Keys<'_, K, V>

source

pub fn len(&self) -> usize

source

pub const fn new() -> Self

Makes a new, empty SupersetMap. Does not allocate anything on its own.

source

pub fn values(&self) -> Values<'_, K, V>

source

pub fn values_mut(&mut self) -> ValuesMut<'_, K, V>

source§

impl<K, V> SupersetMap<K, V>
where K: Ord,

source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: Ord + ?Sized,

source

pub fn first_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>>

source

pub fn first_key_value(&self) -> Option<(&K, &V)>

source

pub fn get<Q>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Ord + ?Sized,

source

pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
where K: Borrow<Q>, Q: Ord + ?Sized,

source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Ord + ?Sized,

source

pub fn last_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>>

source

pub fn last_key_value(&self) -> Option<(&K, &V)>

source

pub fn pop_first(&mut self) -> Option<(K, V)>

source

pub fn pop_last(&mut self) -> Option<(K, V)>

source

pub fn range<T, R>(&self, range: R) -> Range<'_, K, V>
where K: Borrow<T>, T: Ord + ?Sized, R: RangeBounds<T>,

source

pub fn range_mut<T, R>(&mut self, range: R) -> RangeMut<'_, K, V>
where K: Borrow<T>, T: Ord + ?Sized, R: RangeBounds<T>,

source

pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
where K: Borrow<Q>, Q: Ord + ?Sized,

source

pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
where K: Borrow<Q>, Q: Ord + ?Sized,

source

pub fn split_off<Q>(&mut self, key: &Q) -> Self
where K: Borrow<Q>, Q: Ord + ?Sized,

source§

impl<K, V> SupersetMap<K, V>
where K: SetOrd,

source

pub fn append(&mut self, other: Self)

Moves all elements from other into self, consuming other. If a key from other is a proper superset of a key in self, the respective key and value from self will be removed before inserting the key and value from other. If a key from other is a subset of a key in self, it won’t be inserted.

source

pub fn contains_proper_subset<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: SetOrd + ?Sized,

Returns true if the map contains a value for a proper subset of the specified key. The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

source

pub fn contains_proper_superset<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: SetOrd + ?Sized,

Returns true if the map contains a value for a proper superset of the specified key. The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

source

pub fn contains_subset<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: SetOrd + ?Sized,

Returns true if the map contains a value for a subset of the specified key. The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

source

pub fn contains_superset<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: SetOrd + ?Sized,

Returns true if the map contains a value for a superset of the specified key. The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

source

pub fn get_greatest_proper_subset<Q>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q>, Q: SetOrd + ?Sized,

Returns a reference to the value corresponding to the greatest proper subset of key. The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

source

pub fn get_greatest_proper_subset_key_value<Q>( &self, key: &Q ) -> Option<(&K, &V)>
where K: Borrow<Q>, Q: SetOrd + ?Sized,

Returns a reference to the key-value pair corresponding to the greatest proper subset of the supplied key. The supplied key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type

source

pub fn get_greatest_subset<Q>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q>, Q: SetOrd + ?Sized,

Returns a reference to the value corresponding to the greatest subset of key. The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

source

pub fn get_greatest_subset_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
where K: Borrow<Q>, Q: SetOrd + ?Sized,

Returns a reference to the key-value pair corresponding to the greatest subset of the supplied key. The supplied key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type

source

pub fn get_least_proper_superset<Q>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q>, Q: SetOrd + ?Sized,

Returns a reference to the value corresponding to the least proper superset of key. The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

source

pub fn get_least_proper_superset_key_value<Q>( &self, key: &Q ) -> Option<(&K, &V)>
where K: Borrow<Q>, Q: SetOrd + ?Sized,

Returns a reference to the key-value pair corresponding to the least proper superset of the supplied key. The supplied key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type

source

pub fn get_least_superset<Q>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q>, Q: SetOrd + ?Sized,

Returns a reference to the value corresponding to the least superset of key. The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

source

pub fn get_least_superset_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
where K: Borrow<Q>, Q: SetOrd + ?Sized,

Returns a reference to the key-value pair corresponding to the least superset of the supplied key. The supplied key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type

source

pub fn insert(&mut self, key: K, value: V) -> bool

(key, value) is inserted iff there doesn’t already exist a K that is a superset of key. In the event (key, value) will be inserted, all (K, V)s where the K is a subset of key are first removed before inserting.

source

pub fn remove_greatest_proper_subset<Q>(&mut self, key: &Q) -> Option<(K, V)>
where K: Borrow<Q>, Q: SetOrd + ?Sized,

Removes the greatest proper subset of key from the map, returning the key and value if such a subset exists. The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

source

pub fn remove_greatest_subset<Q>(&mut self, key: &Q) -> Option<(K, V)>
where K: Borrow<Q>, Q: SetOrd + ?Sized,

Removes the greatest subset of key from the map, returning the key and value if such a subset exists. The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

source

pub fn remove_least_proper_superset<Q>(&mut self, key: &Q) -> Option<(K, V)>
where K: Borrow<Q>, Q: SetOrd + ?Sized,

Removes the least proper superset of key from the map, returning the key and value if such a superset exists. The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

source

pub fn remove_least_superset<Q>(&mut self, key: &Q) -> Option<(K, V)>
where K: Borrow<Q>, Q: SetOrd + ?Sized,

Removes the least superset of key from the map, returning the key and value if such a superset exists. The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

source

pub fn remove_proper_subsets<Q>(&mut self, key: &Q) -> usize
where K: Borrow<Q>, Q: SetOrd + ?Sized,

Removes all proper subsets of key from the map, returning the count removed. The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

§Overflow Behavior

The method does no guarding against overflows, so the removal of more than usize::MAX elements either produces the wrong result or panics. If debug assertions are enabled, a panic is guaranteed.

§Panics

This function might panic if the number of elements removed is greater than usize::MAX.

source

pub fn remove_proper_supersets<Q>(&mut self, key: &Q) -> usize
where K: Borrow<Q>, Q: SetOrd + ?Sized,

Removes all proper supersets of key from the map, returning the count removed. The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

§Overflow Behavior

The method does no guarding against overflows, so the removal of more than usize::MAX elements either produces the wrong result or panics. If debug assertions are enabled, a panic is guaranteed.

§Panics

This function might panic if the number of elements removed is greater than usize::MAX.

source

pub fn remove_subsets<Q>(&mut self, key: &Q) -> usize
where K: Borrow<Q>, Q: SetOrd + ?Sized,

Removes all subsets of key from the map, returning the count removed. The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

§Overflow Behavior

The method does no guarding against overflows, so the removal of more than usize::MAX elements either produces the wrong result or panics. If debug assertions are enabled, a panic is guaranteed.

§Panics

This function might panic if the number of elements removed is greater than usize::MAX.

source

pub fn remove_supersets<Q>(&mut self, key: &Q) -> usize
where K: Borrow<Q>, Q: SetOrd + ?Sized,

Removes all supersets of key from the map, returning the count removed. The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

§Overflow Behavior

The method does no guarding against overflows, so the removal of more than usize::MAX elements either produces the wrong result or panics. If debug assertions are enabled, a panic is guaranteed.

§Panics

This function might panic if the number of elements removed is greater than usize::MAX.

source

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

Retains only the elements specified by the predicate. In other words, remove all pairs (k, v) for which f(&k, &mut v) returns false. The elements are visited in ascending key order.

Trait Implementations§

source§

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

source§

fn clone(&self) -> SupersetMap<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 SupersetMap<K, V>

source§

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

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

impl<K, V> Default for SupersetMap<K, V>

source§

fn default() -> Self

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

impl<'a, K, V> Extend<(&'a K, &'a V)> for SupersetMap<K, V>
where K: SetOrd + Copy, V: Copy,

source§

fn extend<T: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: 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<K, V> Extend<(K, V)> for SupersetMap<K, V>
where K: SetOrd,

source§

fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: 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<K, V, const N: usize> From<[(K, V); N]> for SupersetMap<K, V>
where K: SetOrd,

source§

fn from(value: [(K, V); N]) -> Self

Converts to this type from the input type.
source§

impl<K, V> FromIterator<(K, V)> for SupersetMap<K, V>
where K: SetOrd,

source§

fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl<K: Hash, V: Hash> Hash for SupersetMap<K, V>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<K, Q, V> Index<&Q> for SupersetMap<K, V>
where K: Borrow<Q> + Ord, Q: Ord + ?Sized,

§

type Output = V

The returned type after indexing.
source§

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

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

impl<'a, K, V> IntoIterator for &'a SupersetMap<K, V>

§

type Item = (&'a K, &'a V)

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, K, V>

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, K, V> IntoIterator for &'a mut SupersetMap<K, V>

§

type Item = (&'a K, &'a mut V)

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a, K, V>

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<K, V> IntoIterator for SupersetMap<K, V>

§

type Item = (K, V)

The type of the elements being iterated over.
§

type IntoIter = IntoIter<K, V>

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<K: Ord, V: Ord> Ord for SupersetMap<K, V>

source§

fn cmp(&self, other: &SupersetMap<K, V>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<K: PartialEq, V: PartialEq> PartialEq for SupersetMap<K, V>

source§

fn eq(&self, other: &SupersetMap<K, V>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<K: PartialOrd, V: PartialOrd> PartialOrd for SupersetMap<K, V>

source§

fn partial_cmp(&self, other: &SupersetMap<K, V>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<K: Eq, V: Eq> Eq for SupersetMap<K, V>

source§

impl<K, V> StructuralPartialEq for SupersetMap<K, V>

Auto Trait Implementations§

§

impl<K, V> Freeze for SupersetMap<K, V>

§

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

§

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

§

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

§

impl<K, V> Unpin for SupersetMap<K, V>

§

impl<K, V> UnwindSafe for SupersetMap<K, V>

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.