Struct collective::rangemap::RangeMap
source · pub struct RangeMap<RK: Ord + Copy, V> { /* private fields */ }
Expand description
A dictionary keyed by ranges
Useful for sharding implementations
Powereded by a BTreeMap under the hood.
Note: Ranges are inclusive.
Implementations§
source§impl<RK: Ord + Copy, V> RangeMap<RK, V>
impl<RK: Ord + Copy, V> RangeMap<RK, V>
sourcepub fn insert(
&mut self,
start: RK,
end: RK,
value: V,
) -> Result<(), RangeMapError>
pub fn insert( &mut self, start: RK, end: RK, value: V, ) -> Result<(), RangeMapError>
Inserts a value in the map at the given range
A RangeMapError::InvalidRange
error will be returned if the range
is invalid.
A RangeMapError::RangeOverlap
error will be returned if the
insertion would result in an overlap.
sourcepub fn get(&self, key: (RK, RK)) -> Option<&V>
pub fn get(&self, key: (RK, RK)) -> Option<&V>
Looks up a value at the specified range
If the range does not match, None
is returned.
sourcepub fn get_mut(&mut self, key: (RK, RK)) -> Option<&mut V>
pub fn get_mut(&mut self, key: (RK, RK)) -> Option<&mut V>
Looks up a mutable value at the specified range
If the range does not match, None
is returned.
sourcepub fn lookup(&self, key: RK) -> Option<&V>
pub fn lookup(&self, key: RK) -> Option<&V>
Looks up a value at the specified key
If the key is within an existing range, the matching value is
returned. Otherwise, None
is returned.
sourcepub fn overlaps(&self, start: RK, end: RK) -> bool
pub fn overlaps(&self, start: RK, end: RK) -> bool
Checks whether the provided range has any overlaps.
sourcepub fn remove(&mut self, key: RK) -> Option<V>
pub fn remove(&mut self, key: RK) -> Option<V>
Looks up a value at the specified key and removes it from the dictionary.
Lookup works just like [lookup
].
Trait Implementations§
Auto Trait Implementations§
impl<RK, V> Freeze for RangeMap<RK, V>
impl<RK, V> RefUnwindSafe for RangeMap<RK, V>where
RK: RefUnwindSafe,
V: RefUnwindSafe,
impl<RK, V> Send for RangeMap<RK, V>
impl<RK, V> Sync for RangeMap<RK, V>
impl<RK, V> Unpin for RangeMap<RK, V>
impl<RK, V> UnwindSafe for RangeMap<RK, V>where
RK: RefUnwindSafe,
V: RefUnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)