Struct rangemap::map::RangeMap

source ·
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>

source

pub fn new() -> Self

Makes a new empty RangeMap.

source

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

Gets an iterator over all pairs of key range and value, ordered by key range.

The iterator element type is (&'a Range<K>, &'a V).

source

pub fn clear(&mut self)

Clears the map, removing all elements.

source

pub fn len(&self) -> usize

Returns the number of elements in the map.

source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

source§

impl<K, V> RangeMap<K, V>
where K: Ord + Clone,

source

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.

source

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.

source

pub fn contains_key(&self, key: &K) -> bool

Returns true if any range in the map covers the specified key.

source

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>.

source

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.

source

pub fn overlaps(&self, range: &Range<K>) -> bool

Returns true if any range in the map completely or partially overlaps the given range.

source

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.

source

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>
where K: Ord + Clone, V: Eq + Clone,

source

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.

source

pub fn remove(&mut self, range: Range<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.

Trait Implementations§

source§

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

source§

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

source§

fn default() -> Self

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

impl<K, V> Extend<(Range<K>, V)> for RangeMap<K, V>
where K: Ord + Clone, V: Eq + Clone,

source§

fn extend<T: IntoIterator<Item = (Range<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: Ord + Clone, V: Eq + Clone, const N: usize> From<[(Range<K>, V); N]> for RangeMap<K, V>

source§

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

Converts to this type from the input type.
source§

impl<K, V> FromIterator<(Range<K>, V)> for RangeMap<K, V>
where K: Ord + Clone, V: Eq + Clone,

source§

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

Creates a value from an iterator. Read more
source§

impl<K, V> Hash for RangeMap<K, V>
where K: Hash, V: Hash,

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

§

type Item = (Range<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, V> Ord for RangeMap<K, V>
where K: Ord, V: Ord,

source§

fn cmp(&self, other: &RangeMap<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, V> PartialEq for RangeMap<K, V>
where K: PartialEq, V: PartialEq,

source§

fn eq(&self, other: &RangeMap<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, V> PartialOrd for RangeMap<K, V>
where K: PartialOrd, V: PartialOrd,

source§

fn partial_cmp(&self, other: &RangeMap<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 RangeMap<K, V>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<K, V> UnwindSafe for RangeMap<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.