Struct rangemap::inclusive_map::RangeInclusiveMap
source · pub struct RangeInclusiveMap<K, V, StepFnsT = K> { /* private fields */ }
Expand description
A map whose keys are stored as ranges bounded
inclusively below and above (start..=end)
.
Contiguous and overlapping ranges that map to the same value are coalesced into a single range.
Successor and predecessor functions must be provided for
the key type K
, so that we can detect adjacent but non-overlapping
(closed) ranges. (This is not a problem for half-open ranges,
because adjacent ranges can be detected using equality of range ends alone.)
You can provide these functions either by implementing the
StepLite
trait for your key type K
, or,
if this is impossible because of Rust’s “orphan rules”,
you can provide equivalent free functions using the StepFnsT
type parameter.
StepLite
is implemented for all standard integer types,
but not for any third party crate types.
Implementations§
source§impl<K, V, StepFnsT> RangeInclusiveMap<K, V, StepFnsT>
impl<K, V, StepFnsT> RangeInclusiveMap<K, V, StepFnsT>
source§impl<K, V> RangeInclusiveMap<K, V, K>
impl<K, V> RangeInclusiveMap<K, V, K>
source§impl<K, V, StepFnsT> RangeInclusiveMap<K, V, StepFnsT>
impl<K, V, StepFnsT> RangeInclusiveMap<K, V, StepFnsT>
sourcepub fn new_with_step_fns() -> Self
pub fn new_with_step_fns() -> Self
Makes a new empty RangeInclusiveMap
, specifying successor and
predecessor functions defined separately from K
itself.
This is useful as a workaround for Rust’s “orphan rules”,
which prevent you from implementing StepLite
for K
if K
is a foreign type.
NOTE: This will likely be deprecated and then eventually removed once the standard library’s Step trait is stabilised, as most crates will then likely implement Step for their types where appropriate.
See this issue for details about that stabilization process.
sourcepub fn get(&self, key: &K) -> Option<&V>
pub fn get(&self, key: &K) -> Option<&V>
Returns a reference to the value corresponding to the given key, if the key is covered by any range in the map.
sourcepub fn get_key_value(&self, key: &K) -> Option<(&RangeInclusive<K>, &V)>
pub fn get_key_value(&self, key: &K) -> Option<(&RangeInclusive<K>, &V)>
Returns the range-value pair (as a pair of references) corresponding to the given key, if the key is covered by any range in the map.
sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Returns true
if any range in the map covers the specified key.
sourcepub fn insert(&mut self, range: RangeInclusive<K>, value: V)
pub fn insert(&mut self, range: RangeInclusive<K>, value: V)
Insert a pair of key range and value into the map.
If the inserted range partially or completely overlaps any existing range in the map, then the existing range (or ranges) will be partially or completely replaced by the inserted range.
If the inserted range either overlaps or is immediately adjacent any existing range mapping to the same value, then the ranges will be coalesced into a single contiguous range.
§Panics
Panics if range start > end
.
sourcepub fn remove(&mut self, range: RangeInclusive<K>)
pub fn remove(&mut self, range: RangeInclusive<K>)
Removes a range from the map, if all or any of it was present.
If the range to be removed partially overlaps any ranges in the map, then those ranges will be contracted to no longer cover the removed range.
§Panics
Panics if range start > end
.
sourcepub fn gaps<'a>(
&'a self,
outer_range: &'a RangeInclusive<K>
) -> Gaps<'a, K, V, StepFnsT> ⓘ
pub fn gaps<'a>( &'a self, outer_range: &'a RangeInclusive<K> ) -> Gaps<'a, K, V, StepFnsT> ⓘ
Gets an iterator over all the maximally-sized ranges
contained in outer_range
that are not covered by
any range stored in the map.
The iterator element type is RangeInclusive<K>
.
sourcepub fn overlapping<R: Borrow<RangeInclusive<K>>>(
&self,
range: R
) -> Overlapping<'_, K, V, R> ⓘ
pub fn overlapping<R: Borrow<RangeInclusive<K>>>( &self, range: R ) -> Overlapping<'_, K, V, R> ⓘ
Gets an iterator over all the stored ranges that are either partially or completely overlapped by the given range.
sourcepub fn overlaps(&self, range: &RangeInclusive<K>) -> bool
pub fn overlaps(&self, range: &RangeInclusive<K>) -> bool
Returns true
if any range in the map completely or partially
overlaps the given range.
sourcepub fn first_range_value(&self) -> Option<(&RangeInclusive<K>, &V)>
pub fn first_range_value(&self) -> Option<(&RangeInclusive<K>, &V)>
Returns the first range-value pair in this map, if one exists. The range in this pair is the minimum range in the map.
sourcepub fn last_range_value(&self) -> Option<(&RangeInclusive<K>, &V)>
pub fn last_range_value(&self) -> Option<(&RangeInclusive<K>, &V)>
Returns the last range-value pair in this map, if one exists. The range in this pair is the maximum range in the map.
Trait Implementations§
source§impl<K: Clone, V: Clone, StepFnsT: Clone> Clone for RangeInclusiveMap<K, V, StepFnsT>
impl<K: Clone, V: Clone, StepFnsT: Clone> Clone for RangeInclusiveMap<K, V, StepFnsT>
source§fn clone(&self) -> RangeInclusiveMap<K, V, StepFnsT>
fn clone(&self) -> RangeInclusiveMap<K, V, StepFnsT>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<K, V> Debug for RangeInclusiveMap<K, V>
impl<K, V> Debug for RangeInclusiveMap<K, V>
source§impl<K, V, StepFnsT> Default for RangeInclusiveMap<K, V, StepFnsT>
impl<K, V, StepFnsT> Default for RangeInclusiveMap<K, V, StepFnsT>
source§impl<K, V> Extend<(RangeInclusive<K>, V)> for RangeInclusiveMap<K, V>
impl<K, V> Extend<(RangeInclusive<K>, V)> for RangeInclusiveMap<K, V>
source§fn extend<T: IntoIterator<Item = (RangeInclusive<K>, V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (RangeInclusive<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: Ord + Clone + StepLite, V: Eq + Clone, const N: usize> From<[(RangeInclusive<K>, V); N]> for RangeInclusiveMap<K, V>
impl<K: Ord + Clone + StepLite, V: Eq + Clone, const N: usize> From<[(RangeInclusive<K>, V); N]> for RangeInclusiveMap<K, V>
source§fn from(value: [(RangeInclusive<K>, V); N]) -> Self
fn from(value: [(RangeInclusive<K>, V); N]) -> Self
source§impl<K, V> FromIterator<(RangeInclusive<K>, V)> for RangeInclusiveMap<K, V>
impl<K, V> FromIterator<(RangeInclusive<K>, V)> for RangeInclusiveMap<K, V>
source§fn from_iter<T: IntoIterator<Item = (RangeInclusive<K>, V)>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = (RangeInclusive<K>, V)>>(iter: T) -> Self
source§impl<K, V, StepFnsT> Hash for RangeInclusiveMap<K, V, StepFnsT>
impl<K, V, StepFnsT> Hash for RangeInclusiveMap<K, V, StepFnsT>
source§impl<K, V> IntoIterator for RangeInclusiveMap<K, V>
impl<K, V> IntoIterator for RangeInclusiveMap<K, V>
source§impl<K, V, StepFnsT> Ord for RangeInclusiveMap<K, V, StepFnsT>
impl<K, V, StepFnsT> Ord for RangeInclusiveMap<K, V, StepFnsT>
source§fn cmp(&self, other: &RangeInclusiveMap<K, V, StepFnsT>) -> Ordering
fn cmp(&self, other: &RangeInclusiveMap<K, V, StepFnsT>) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<K, V, StepFnsT> PartialEq for RangeInclusiveMap<K, V, StepFnsT>
impl<K, V, StepFnsT> PartialEq for RangeInclusiveMap<K, V, StepFnsT>
source§fn eq(&self, other: &RangeInclusiveMap<K, V, StepFnsT>) -> bool
fn eq(&self, other: &RangeInclusiveMap<K, V, StepFnsT>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<K, V, StepFnsT> PartialOrd for RangeInclusiveMap<K, V, StepFnsT>where
K: PartialOrd,
V: PartialOrd,
impl<K, V, StepFnsT> PartialOrd for RangeInclusiveMap<K, V, StepFnsT>where
K: PartialOrd,
V: PartialOrd,
source§fn partial_cmp(
&self,
other: &RangeInclusiveMap<K, V, StepFnsT>
) -> Option<Ordering>
fn partial_cmp( &self, other: &RangeInclusiveMap<K, V, StepFnsT> ) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more