Struct RangeMap

Source
pub struct RangeMap<K: Ord + Copy + Gap, V: Clone + Eq> { /* private fields */ }
Expand description

A map from ranges to values.

This map can be cloned efficiently. If the map is modified after being cloned, the relevant parts of the map’s internal structure will be copied lazily.

Implementations§

Source§

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

Source

pub fn is_empty(&self) -> bool

Whether this map contains any entries.

Source

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

Searches the map for a range that contains the given key.

Returns the range and value if such a range is found.

Source

pub fn last_range(&self) -> Option<&Range<K>>

The last range stored in this map.

Source

pub fn find_gap_end(&self, gap: u64, upper_bound: &K) -> K

Find a gap that is at least as large as the given gap and is less than the given upper bound.

Returns the end of the gap, which might above or below the entries in the map.

Source

pub fn remove(&mut self, range: Range<K>) -> Vec<V>

Remove the entry with the given key from the map.

If the key was present in the map, returns the value previously stored at the given key.

Source

pub fn insert(&mut self, range: Range<K>, value: V)

Inserts a range with the given value.

The keys included in the given range are now associated with the given value. If those keys were previously associated with another value, are no longer associated with that previous value.

This method can cause one or more values in the map to be dropped if the all of the keys associated with those values are contained within the given range.

If the inserted range is directly adjacent to another range with an equal value, the inserted range will be merged with the adjacent ranges.

Source

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

Iterate through the keys and values stored in the map.

Source

pub fn range(&self, bounds: impl RangeBounds<K>) -> Iter<'_, K, V>

Iterate through the keys and values stored in the given range in the map.

Source

pub fn find_at_or_after(&self, key: K) -> Option<(&Range<K>, &V)>

Find the first range in the map that starts at or after the given key.

Trait Implementations§

Source§

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

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

Source§

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

Source§

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.