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>
impl<K, V, C: Storage<Item<AnyRange<K>, V>>> RangeMap<K, V, C>
pub fn len(&self) -> K::Len
pub fn bounded_len(&self) -> Option<K::Len>where
K: Measure + PartialEnum,
pub fn is_empty(&self) -> boolwhere
K: Measure + PartialEnum,
pub fn range_count(&self) -> usize
Sourcepub fn intersects<R: AsRange<Item = K>>(&self, key: R) -> bool
pub fn intersects<R: AsRange<Item = K>>(&self, key: R) -> bool
§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.
Sourcepub fn contains_key(&self, key: K) -> bool
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.
Sourcepub fn get(&self, key: K) -> Option<&V>
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.
pub fn iter(&self) -> Iter<'_, K, V, C> ⓘ
Source§impl<K, V, C: Storage<Item<AnyRange<K>, V>>> RangeMap<K, V, C>
impl<K, V, C: Storage<Item<AnyRange<K>, V>>> RangeMap<K, V, C>
Sourcepub fn update<R: AsRange<Item = K>, F>(&mut self, key: R, f: F)
pub fn update<R: AsRange<Item = K>, F>(&mut self, key: R, f: F)
§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.
pub fn insert_disconnected<R: IntoRange<Item = K>>(
&mut self,
key: R,
value: V,
) -> Result<(), (AnyRange<K>, V)>where
K: PartialEnum + Measure,
Sourcepub fn insert<R: IntoRange<Item = K>>(&mut self, key: R, value: V)
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).
Sourcepub fn remove<R: AsRange<Item = K>>(&mut self, key: R)
pub fn remove<R: AsRange<Item = K>>(&mut self, key: R)
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).