pub struct RangeMap<T, V> { /* private fields */ }
Expand description
A set of characters. Optionally, each character in the set may be associated with some data.
Implementations
sourceimpl<T: Debug + PrimInt, V: Clone + Debug + Eq> RangeMap<T, V>
impl<T: Debug + PrimInt, V: Clone + Debug + Eq> RangeMap<T, V>
sourcepub fn try_from_iter<I: IntoIterator<Item = (Range<T>, V)>>(
iter: I
) -> Result<RangeMap<T, V>, OverlapError<T, V>>
pub fn try_from_iter<I: IntoIterator<Item = (Range<T>, V)>>(
iter: I
) -> Result<RangeMap<T, V>, OverlapError<T, V>>
Builds a RangeMap
from an iterator over pairs. If any ranges overlap, they should map to
the same value. If not, returns an OverlapError
.
sourcepub fn num_ranges(&self) -> usize
pub fn num_ranges(&self) -> usize
Returns the number of mapped ranges.
Note that this is not usually the same as the number of mapped values.
sourcepub fn ranges_values<'a>(&'a self) -> Iter<'a, (Range<T>, V)>
pub fn ranges_values<'a>(&'a self) -> Iter<'a, (Range<T>, V)>
Iterates over all the mapped ranges and values.
sourcepub fn keys_values<'a>(&'a self) -> PairIter<'a, T, V>ⓘNotable traits for PairIter<'a, T, V>impl<'a, T: PrimInt, V> Iterator for PairIter<'a, T, V> type Item = (T, &'a V);
pub fn keys_values<'a>(&'a self) -> PairIter<'a, T, V>ⓘNotable traits for PairIter<'a, T, V>impl<'a, T: PrimInt, V> Iterator for PairIter<'a, T, V> type Item = (T, &'a V);
Iterates over all mappings.
sourcepub fn get(&self, x: T) -> Option<&V>
pub fn get(&self, x: T) -> Option<&V>
Finds the value that x
maps to, if it exists.
Runs in O(log n)
time, where n
is the number of mapped ranges.
sourcepub fn intersection(&self, other: &RangeSet<T>) -> RangeMap<T, V>
pub fn intersection(&self, other: &RangeSet<T>) -> RangeMap<T, V>
Returns those mappings whose keys belong to the given set.
sourcepub fn num_keys(&self) -> usize
pub fn num_keys(&self) -> usize
Counts the number of mapped keys.
This saturates at usize::MAX
.
sourcepub fn to_range_set(&self) -> RangeSet<T>
pub fn to_range_set(&self) -> RangeSet<T>
Returns the set of mapped chars, forgetting what they are mapped to.
sourcepub fn map_values<F>(&mut self, f: F)where
F: FnMut(&V) -> V,
pub fn map_values<F>(&mut self, f: F)where
F: FnMut(&V) -> V,
Modifies the values in place.
sourcepub fn retain_values<F>(&mut self, f: F)where
F: FnMut(&V) -> bool,
pub fn retain_values<F>(&mut self, f: F)where
F: FnMut(&V) -> bool,
Modifies this map to contain only those mappings with values v
satisfying f(v)
.
sourcepub fn as_mut_slice(&mut self) -> &mut [(Range<T>, V)]
pub fn as_mut_slice(&mut self) -> &mut [(Range<T>, V)]
Returns a mutable view into this map.
The ranges should not be modified, since that might violate our invariants.
This method will eventually be removed, probably once anonymous return values allow is to write a values_mut() iterator more easily.
Trait Implementations
sourceimpl<T: Debug + PrimInt, V: Clone + Debug + Eq> FromIterator<(Range<T>, V)> for RangeMap<T, V>
impl<T: Debug + PrimInt, V: Clone + Debug + Eq> FromIterator<(Range<T>, V)> for RangeMap<T, V>
sourcefn from_iter<I: IntoIterator<Item = (Range<T>, V)>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = (Range<T>, V)>>(iter: I) -> Self
Builds a RangeMap
from an iterator over pairs. If any ranges overlap, they must map to
the same value.
Panics
Panics if there are ranges that overlap and do not map to the same value. If you are not
sure whether this could happen, use RangeMap::try_from_iter
instead.