Struct rangemap::RangeInclusiveMap[][src]

pub struct RangeInclusiveMap<K, V, StepFnsT = K> { /* fields omitted */ }

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

impl<K, V> RangeInclusiveMap<K, V, K> where
    K: Ord + Clone + StepLite,
    V: Eq + Clone
[src]

pub fn new() -> Self[src]

Makes a new empty RangeInclusiveMap.

impl<K, V, StepFnsT> RangeInclusiveMap<K, V, StepFnsT> where
    K: Ord + Clone,
    V: Eq + Clone,
    StepFnsT: StepFns<K>, 
[src]

pub fn new_with_step_fns() -> Self[src]

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.

pub fn get(&self, key: &K) -> Option<&V>[src]

Returns a reference to the value corresponding to the given key, if the key is covered by any range in the map.

pub fn get_key_value(&self, key: &K) -> Option<(&RangeInclusive<K>, &V)>[src]

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.

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

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

pub fn iter(&self) -> impl Iterator<Item = (&RangeInclusive<K>, &V)>[src]

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

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

pub fn insert(&mut self, range: RangeInclusive<K>, value: V)[src]

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.

pub fn remove(&mut self, range: RangeInclusive<K>)[src]

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.

pub fn gaps<'a>(
    &'a self,
    outer_range: &'a RangeInclusive<K>
) -> Gaps<'a, K, V, StepFnsT>
[src]

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

NOTE: Calling gaps eagerly finds the first gap, even if the iterator is never consumed.

Trait Implementations

impl<K: Clone, V: Clone, StepFnsT: Clone> Clone for RangeInclusiveMap<K, V, StepFnsT>[src]

impl<K: Debug, V: Debug> Debug for RangeInclusiveMap<K, V> where
    K: Ord + Clone + StepLite,
    V: Eq + Clone
[src]

impl<K, V> Default for RangeInclusiveMap<K, V, K> where
    K: Ord + Clone + StepLite,
    V: Eq + Clone
[src]

Auto Trait Implementations

impl<K, V, StepFnsT> RefUnwindSafe for RangeInclusiveMap<K, V, StepFnsT> where
    K: RefUnwindSafe,
    StepFnsT: RefUnwindSafe,
    V: RefUnwindSafe

impl<K, V, StepFnsT> Send for RangeInclusiveMap<K, V, StepFnsT> where
    K: Send,
    StepFnsT: Send,
    V: Send

impl<K, V, StepFnsT> Sync for RangeInclusiveMap<K, V, StepFnsT> where
    K: Sync,
    StepFnsT: Sync,
    V: Sync

impl<K, V, StepFnsT> Unpin for RangeInclusiveMap<K, V, StepFnsT> where
    StepFnsT: Unpin

impl<K, V, StepFnsT> UnwindSafe for RangeInclusiveMap<K, V, StepFnsT> where
    K: RefUnwindSafe,
    StepFnsT: UnwindSafe,
    V: RefUnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.