Skip to main content

RangeMap

Struct RangeMap 

Source
pub struct RangeMap<K, V, C: Storage<Item<AnyRange<K>, V>>> { /* private fields */ }
Expand description

Range map.

Implementations§

Source§

impl<K, V, C: Storage<Item<AnyRange<K>, V>>> RangeMap<K, V, C>

Source

pub fn new() -> RangeMap<K, V, C>

Create a new empty map.

Source§

impl<K, V, C: Storage<Item<AnyRange<K>, V>>> RangeMap<K, V, C>

Source

pub fn len(&self) -> K::Len

Source

pub fn bounded_len(&self) -> Option<K::Len>
where K: Measure + PartialEnum,

Source

pub fn is_empty(&self) -> bool
where K: Measure + PartialEnum,

Source

pub fn range_count(&self) -> usize

Source

pub fn intersects<R: AsRange<Item = K>>(&self, key: R) -> bool
where K: PartialEnum + Measure, V: PartialEq,

§Complexity

O(log n), where n is the number of ranges in the map (Self::range_count). A single top-down search through the B-tree locates the (at most one) range intersecting key.

Source

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

§Complexity

O(log n), where n is the number of ranges in the map (Self::range_count). Same single-search cost as Self::get.

Source

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

§Complexity

O(log n), where n is the number of ranges in the map (Self::range_count). A single top-down binary search through the B-tree locates the range containing key.

Source

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

Source

pub fn gaps(&self) -> Gaps<'_, K, V, C> ⓘ

Returns an iterator over the gaps (unbounded keys) of the map.

Source§

impl<K, V, C: Storage<Item<AnyRange<K>, V>>> RangeMap<K, V, C>

Source

pub fn update<R: AsRange<Item = K>, F>(&mut self, key: R, f: F)
where K: Clone + PartialEnum + Measure, F: Fn(Option<&V>) -> Option<V>, V: PartialEq + Clone,

§Complexity

O((k + 1) log n), where n is the number of ranges in the map (Self::range_count) and k is the number of existing ranges that overlap, or are connected to, key. Each of the k affected ranges is merged, split or removed with one O(log n) B-tree operation, on top of the initial O(log n) lookup. This is O(log n) when key only touches a handful of existing ranges (the common case), and O(n log n) in the worst case (key overlaps or connects to every stored range). This primitive underlies RangeMultiMap::insert and RangeMultiMap::remove.

Source

pub fn insert_disconnected<R: IntoRange<Item = K>>( &mut self, key: R, value: V, ) -> Result<(), (AnyRange<K>, V)>
where K: PartialEnum + Measure,

Source

pub fn insert<R: IntoRange<Item = K>>(&mut self, key: R, value: V)

Insert a new key-value binding.

§Complexity

O((k + 1) log n), where n is the number of ranges in the map (Self::range_count) and k is the number of existing ranges that overlap, or are connected to, key. Each of the k affected ranges is merged, split or replaced with one O(log n) B-tree operation, on top of the initial O(log n) lookup. Usually O(log n); worst case (e.g. inserting a range spanning the whole map) is O(n log n).

Source

pub fn remove<R: AsRange<Item = K>>(&mut self, key: R)
where K: Clone + PartialEnum + Measure, V: Clone,

Remove a key.

§Complexity

O((k + 1) log n), where n is the number of ranges in the map (Self::range_count) and k is the number of existing ranges that intersect key. Each intersecting range costs one O(log n) B-tree operation (split, shrink or removal), on top of the initial O(log n) lookup. Usually O(log n); worst case (key intersects every stored range) is O(n log n).

Trait Implementations§

Source§

impl<K: Clone, V: Clone, C: Storage<Item<AnyRange<K>, V>>> Clone for RangeMap<K, V, C>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K: Debug, V: Debug, C: Storage<Item<AnyRange<K>, V>>> Debug for RangeMap<K, V, C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K, V, C: Storage<Item<AnyRange<K>, V>>> Default for RangeMap<K, V, C>

Source§

fn default() -> Self

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

impl<K, V, C: Storage<Item<AnyRange<K>, V>>> Eq for RangeMap<K, V, C>
where K: Measure + PartialEnum + Ord, V: Eq,

Source§

impl<K, V, C: Storage<Item<AnyRange<K>, V>>> Hash for RangeMap<K, V, C>
where K: Hash + PartialEnum, V: Hash,

Source§

fn hash<H: Hasher>(&self, h: &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<'a, K, V, C: Storage<Item<AnyRange<K>, V>>> IntoIterator for &'a RangeMap<K, V, C>

Source§

type Item = (&'a AnyRange<K>, &'a V)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, K, V, C>

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, C: Storage<Item<AnyRange<K>, V>>> IntoIterator for RangeMap<K, V, C>

Source§

type Item = (AnyRange<K>, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<K, V, C>

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, C: Storage<Item<AnyRange<K>, V>>> Ord for RangeMap<K, V, C>
where K: Measure + PartialEnum + Ord, V: Ord,

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl<K, V, C, D> PartialEq<RangeMap<K, V, D>> for RangeMap<K, V, C>
where K: Measure + PartialOrd + PartialEnum, V: PartialEq, C: Storage<Item<AnyRange<K>, V>>, D: Storage<Item<AnyRange<K>, V>>,

Source§

fn eq(&self, other: &RangeMap<K, V, D>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<K, V, C, D> PartialOrd<RangeMap<K, V, D>> for RangeMap<K, V, C>
where K: Measure + PartialOrd + PartialEnum, V: PartialOrd, C: Storage<Item<AnyRange<K>, V>>, D: Storage<Item<AnyRange<K>, V>>,

Source§

fn partial_cmp(&self, other: &RangeMap<K, V, D>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

§

impl<K, V, C> Freeze for RangeMap<K, V, C>
where RawBTree<Item<AnyRange<K>, V>, C>: Freeze,

§

impl<K, V, C> RefUnwindSafe for RangeMap<K, V, C>
where RawBTree<Item<AnyRange<K>, V>, C>: RefUnwindSafe,

§

impl<K, V, C> Send for RangeMap<K, V, C>
where RawBTree<Item<AnyRange<K>, V>, C>: Send,

§

impl<K, V, C> Sync for RangeMap<K, V, C>
where RawBTree<Item<AnyRange<K>, V>, C>: Sync,

§

impl<K, V, C> Unpin for RangeMap<K, V, C>
where RawBTree<Item<AnyRange<K>, V>, C>: Unpin,

§

impl<K, V, C> UnsafeUnpin for RangeMap<K, V, C>
where RawBTree<Item<AnyRange<K>, V>, C>: UnsafeUnpin,

§

impl<K, V, C> UnwindSafe for RangeMap<K, V, C>
where RawBTree<Item<AnyRange<K>, V>, C>: UnwindSafe,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.