pub struct RangeMap<K, V> { /* private fields */ }
Expand description
A map whose keys are stored as (half-open) ranges bounded
inclusively below and exclusively above (start..end)
.
Contiguous and overlapping ranges that map to the same value are coalesced into a single range.
Implementations§
source§impl<K, V> RangeMap<K, V>
impl<K, V> RangeMap<K, V>
source§impl<K, V> RangeMap<K, V>
impl<K, V> RangeMap<K, V>
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<(&Range<K>, &V)>
pub fn get_key_value(&self, key: &K) -> Option<(&Range<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 gaps<'a>(&'a self, outer_range: &'a Range<K>) -> Gaps<'a, K, V> ⓘ
pub fn gaps<'a>(&'a self, outer_range: &'a Range<K>) -> Gaps<'a, K, V> ⓘ
Gets an iterator over all the maximally-sized ranges
contained in outer_range
that are not covered by
any range stored in the map.
If the start and end of the outer range are the same and it does not overlap any stored range, then a single empty gap will be returned.
The iterator element type is Range<K>
.
sourcepub fn overlapping<R: Borrow<Range<K>>>(
&self,
range: R
) -> Overlapping<'_, K, V, R> ⓘ
pub fn overlapping<R: Borrow<Range<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: &Range<K>) -> bool
pub fn overlaps(&self, range: &Range<K>) -> bool
Returns true
if any range in the map completely or partially
overlaps the given range.
sourcepub fn first_range_value(&self) -> Option<(&Range<K>, &V)>
pub fn first_range_value(&self) -> Option<(&Range<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<(&Range<K>, &V)>
pub fn last_range_value(&self) -> Option<(&Range<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.
source§impl<K, V> RangeMap<K, V>
impl<K, V> RangeMap<K, V>
sourcepub fn insert(&mut self, range: Range<K>, value: V)
pub fn insert(&mut self, range: Range<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
.
Trait Implementations§
source§impl<K, V> Extend<(Range<K>, V)> for RangeMap<K, V>
impl<K, V> Extend<(Range<K>, V)> for RangeMap<K, V>
source§fn extend<T: IntoIterator<Item = (Range<K>, V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (Range<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, V: Eq + Clone, const N: usize> From<[(Range<K>, V); N]> for RangeMap<K, V>
impl<K: Ord + Clone, V: Eq + Clone, const N: usize> From<[(Range<K>, V); N]> for RangeMap<K, V>
source§impl<K, V> FromIterator<(Range<K>, V)> for RangeMap<K, V>
impl<K, V> FromIterator<(Range<K>, V)> for RangeMap<K, V>
source§impl<K, V> IntoIterator for RangeMap<K, V>
impl<K, V> IntoIterator for RangeMap<K, V>
source§impl<K, V> Ord for RangeMap<K, V>
impl<K, V> Ord for RangeMap<K, V>
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<K, V> PartialEq for RangeMap<K, V>
impl<K, V> PartialEq for RangeMap<K, V>
source§impl<K, V> PartialOrd for RangeMap<K, V>where
K: PartialOrd,
V: PartialOrd,
impl<K, V> PartialOrd for RangeMap<K, V>where
K: PartialOrd,
V: PartialOrd,
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