Struct superset_map::SupersetMap
source · 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::insert
ed, 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 K
s 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>
impl<K, V> SupersetMap<K, V>
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Read BTreeMap::clear
.
sourcepub fn into_keys(self) -> IntoKeys<K, V>
pub fn into_keys(self) -> IntoKeys<K, V>
Read BTreeMap::into_keys
.
sourcepub fn into_values(self) -> IntoValues<K, V>
pub fn into_values(self) -> IntoValues<K, V>
Read BTreeMap::into_values
.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Read BTreeMap::is_empty
.
sourcepub fn iter(&self) -> Iter<'_, K, V>
pub fn iter(&self) -> Iter<'_, K, V>
Read BTreeMap::iter
.
sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V>
pub fn iter_mut(&mut self) -> IterMut<'_, K, V>
Read BTreeMap::iter_mut
.
sourcepub fn keys(&self) -> Keys<'_, K, V>
pub fn keys(&self) -> Keys<'_, K, V>
Read BTreeMap::keys
.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Read BTreeMap::len
.
sourcepub const fn new() -> Self
pub const fn new() -> Self
Makes a new, empty SupersetMap
.
Does not allocate anything on its own.
sourcepub fn values(&self) -> Values<'_, K, V>
pub fn values(&self) -> Values<'_, K, V>
Read BTreeMap::values
.
sourcepub fn values_mut(&mut self) -> ValuesMut<'_, K, V>
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V>
Read BTreeMap::values_mut
.
source§impl<K, V> SupersetMap<K, V>where
K: Ord,
impl<K, V> SupersetMap<K, V>where
K: Ord,
sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Read BTreeMap::contains_key
.
sourcepub fn first_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>>
pub fn first_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>>
Read BTreeMap::first_entry
.
sourcepub fn first_key_value(&self) -> Option<(&K, &V)>
pub fn first_key_value(&self) -> Option<(&K, &V)>
sourcepub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
Read BTreeMap::get_key_value
.
sourcepub fn last_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>>
pub fn last_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>>
Read BTreeMap::last_entry
.
sourcepub fn last_key_value(&self) -> Option<(&K, &V)>
pub fn last_key_value(&self) -> Option<(&K, &V)>
Read BTreeMap::last_key_value
.
sourcepub fn pop_first(&mut self) -> Option<(K, V)>
pub fn pop_first(&mut self) -> Option<(K, V)>
Read BTreeMap::pop_first
.
sourcepub fn pop_last(&mut self) -> Option<(K, V)>
pub fn pop_last(&mut self) -> Option<(K, V)>
Read BTreeMap::pop_last
.
sourcepub fn range<T, R>(&self, range: R) -> Range<'_, K, V>
pub fn range<T, R>(&self, range: R) -> Range<'_, K, V>
Read BTreeMap::range
.
sourcepub fn range_mut<T, R>(&mut self, range: R) -> RangeMut<'_, K, V>
pub fn range_mut<T, R>(&mut self, range: R) -> RangeMut<'_, K, V>
Read BTreeMap::range_mut
.
sourcepub fn remove<Q>(&mut self, key: &Q) -> Option<V>
pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
Read BTreeMap::remove
.
sourcepub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
Read BTreeMap::remove_entry
.
source§impl<K, V> SupersetMap<K, V>where
K: SetOrd,
impl<K, V> SupersetMap<K, V>where
K: SetOrd,
sourcepub fn append(&mut self, other: Self)
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.
sourcepub fn contains_proper_subset<Q>(&self, key: &Q) -> bool
pub fn contains_proper_subset<Q>(&self, key: &Q) -> bool
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.
sourcepub fn contains_proper_superset<Q>(&self, key: &Q) -> bool
pub fn contains_proper_superset<Q>(&self, key: &Q) -> bool
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.
sourcepub fn contains_subset<Q>(&self, key: &Q) -> bool
pub fn contains_subset<Q>(&self, key: &Q) -> bool
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.
sourcepub fn contains_superset<Q>(&self, key: &Q) -> bool
pub fn contains_superset<Q>(&self, key: &Q) -> bool
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.
sourcepub fn get_greatest_proper_subset<Q>(&self, key: &Q) -> Option<&V>
pub fn get_greatest_proper_subset<Q>(&self, key: &Q) -> Option<&V>
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.
sourcepub fn get_greatest_proper_subset_key_value<Q>(
&self,
key: &Q,
) -> Option<(&K, &V)>
pub fn get_greatest_proper_subset_key_value<Q>( &self, key: &Q, ) -> Option<(&K, &V)>
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
sourcepub fn get_greatest_subset<Q>(&self, key: &Q) -> Option<&V>
pub fn get_greatest_subset<Q>(&self, key: &Q) -> Option<&V>
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.
sourcepub fn get_greatest_subset_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
pub fn get_greatest_subset_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
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
sourcepub fn get_least_proper_superset<Q>(&self, key: &Q) -> Option<&V>
pub fn get_least_proper_superset<Q>(&self, key: &Q) -> Option<&V>
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.
sourcepub fn get_least_proper_superset_key_value<Q>(
&self,
key: &Q,
) -> Option<(&K, &V)>
pub fn get_least_proper_superset_key_value<Q>( &self, key: &Q, ) -> Option<(&K, &V)>
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
sourcepub fn get_least_superset<Q>(&self, key: &Q) -> Option<&V>
pub fn get_least_superset<Q>(&self, key: &Q) -> Option<&V>
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.
sourcepub fn get_least_superset_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
pub fn get_least_superset_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
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
sourcepub fn insert(&mut self, key: K, value: V) -> bool
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.
sourcepub fn remove_greatest_proper_subset<Q>(&mut self, key: &Q) -> Option<(K, V)>
pub fn remove_greatest_proper_subset<Q>(&mut self, key: &Q) -> Option<(K, V)>
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.
sourcepub fn remove_greatest_subset<Q>(&mut self, key: &Q) -> Option<(K, V)>
pub fn remove_greatest_subset<Q>(&mut self, key: &Q) -> Option<(K, V)>
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.
sourcepub fn remove_least_proper_superset<Q>(&mut self, key: &Q) -> Option<(K, V)>
pub fn remove_least_proper_superset<Q>(&mut self, key: &Q) -> Option<(K, V)>
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.
sourcepub fn remove_least_superset<Q>(&mut self, key: &Q) -> Option<(K, V)>
pub fn remove_least_superset<Q>(&mut self, key: &Q) -> Option<(K, V)>
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.
sourcepub fn remove_proper_subsets<Q>(&mut self, key: &Q) -> usize
pub fn remove_proper_subsets<Q>(&mut self, key: &Q) -> usize
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.
sourcepub fn remove_proper_supersets<Q>(&mut self, key: &Q) -> usize
pub fn remove_proper_supersets<Q>(&mut self, key: &Q) -> usize
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.
sourcepub fn remove_subsets<Q>(&mut self, key: &Q) -> usize
pub fn remove_subsets<Q>(&mut self, key: &Q) -> usize
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.
sourcepub fn remove_supersets<Q>(&mut self, key: &Q) -> usize
pub fn remove_supersets<Q>(&mut self, key: &Q) -> usize
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.
Trait Implementations§
source§impl<K: Clone, V: Clone> Clone for SupersetMap<K, V>
impl<K: Clone, V: Clone> Clone for SupersetMap<K, V>
source§fn clone(&self) -> SupersetMap<K, V>
fn clone(&self) -> SupersetMap<K, V>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<K, V> Default for SupersetMap<K, V>
impl<K, V> Default for SupersetMap<K, V>
source§impl<'a, K, V> Extend<(&'a K, &'a V)> for SupersetMap<K, V>
impl<'a, K, V> Extend<(&'a K, &'a V)> for SupersetMap<K, V>
source§fn extend<T: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: 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
)source§impl<K, V> Extend<(K, V)> for SupersetMap<K, V>where
K: SetOrd,
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)
fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: 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
)source§impl<K, V> FromIterator<(K, V)> for SupersetMap<K, V>where
K: SetOrd,
impl<K, V> FromIterator<(K, V)> for SupersetMap<K, V>where
K: SetOrd,
source§impl<K, Q, V> Index<&Q> for SupersetMap<K, V>
impl<K, Q, V> Index<&Q> for SupersetMap<K, V>
source§impl<'a, K, V> IntoIterator for &'a SupersetMap<K, V>
impl<'a, K, V> IntoIterator for &'a SupersetMap<K, V>
source§impl<'a, K, V> IntoIterator for &'a mut SupersetMap<K, V>
impl<'a, K, V> IntoIterator for &'a mut SupersetMap<K, V>
source§impl<K, V> IntoIterator for SupersetMap<K, V>
impl<K, V> IntoIterator for SupersetMap<K, V>
source§impl<K: Ord, V: Ord> Ord for SupersetMap<K, V>
impl<K: Ord, V: Ord> Ord for SupersetMap<K, V>
source§fn cmp(&self, other: &SupersetMap<K, V>) -> Ordering
fn cmp(&self, other: &SupersetMap<K, V>) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<K: PartialOrd, V: PartialOrd> PartialOrd for SupersetMap<K, V>
impl<K: PartialOrd, V: PartialOrd> PartialOrd for SupersetMap<K, V>
impl<K: Eq, V: Eq> Eq for SupersetMap<K, V>
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>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for SupersetMap<K, V>
impl<K, V> Sync for SupersetMap<K, V>
impl<K, V> Unpin for SupersetMap<K, V>
impl<K, V> UnwindSafe for SupersetMap<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)