added overlapping_mut method to map too
This commit is contained in:
parent
59dff2aa78
commit
aa19139e1e
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -10,9 +10,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "btree_monstrousity"
|
||||
version = "0.0.3"
|
||||
version = "0.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e30d101bbd3dff04ef3aae2c6d01bf4d250269a477a20e3d56af229371b4e243"
|
||||
checksum = "b4d0977e9c15f276380f16f2e9594257c258172b23af39ffd2e4cf5971cb38c7"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"rustversion",
|
||||
|
@ -18,7 +18,7 @@ categories = ["data-structures"]
|
||||
[dependencies]
|
||||
serde = {version = "1.0.148", features = ["derive"]}
|
||||
itertools = "0.10.5"
|
||||
btree_monstrousity = {version ="0.0.3", features = ["btree_drain_filter"]}
|
||||
btree_monstrousity = {version ="0.0.4", features = ["btree_drain_filter"]}
|
||||
either = "1.8.1"
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -420,6 +420,54 @@ where
|
||||
.range(start_comp, start_bound, end_comp, end_bound)
|
||||
}
|
||||
|
||||
/// Returns an mutable iterator over every entry in the map that
|
||||
/// overlaps the given range in ascending order.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the given range is an invalid range. See [`Invalid
|
||||
/// Ranges`](https://docs.rs/range_bounds_map/latest/range_bounds_map/index.html#Invalid-RangeBounds)
|
||||
/// for more details.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use range_bounds_map::test_ranges::ie;
|
||||
/// use range_bounds_map::RangeBoundsMap;
|
||||
///
|
||||
/// let mut map = RangeBoundsMap::from_slice_strict([
|
||||
/// (ie(1, 4), false),
|
||||
/// (ie(4, 8), true),
|
||||
/// (ie(8, 100), false),
|
||||
/// ])
|
||||
/// .unwrap();
|
||||
///
|
||||
/// for (range, value) in map.overlapping_mut(ie(3, 7)) {
|
||||
/// if *range == ie(4, 8) {
|
||||
/// *value = false
|
||||
/// } else {
|
||||
/// *value = true
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
pub fn overlapping_mut<Q>(
|
||||
&mut self,
|
||||
range: Q,
|
||||
) -> impl DoubleEndedIterator<Item = (&K, &mut V)>
|
||||
where
|
||||
Q: NiceRange<I>,
|
||||
{
|
||||
invalid_range_panic(range);
|
||||
|
||||
let start_comp = overlapping_start_comp(range.start());
|
||||
let end_comp = overlapping_end_comp(range.end());
|
||||
|
||||
let start_bound = SearchBoundCustom::Included;
|
||||
let end_bound = SearchBoundCustom::Included;
|
||||
|
||||
self.inner
|
||||
.range_mut(start_comp, start_bound, end_comp, end_bound)
|
||||
}
|
||||
|
||||
/// Returns a reference to the value corresponding to the range in
|
||||
/// the map that overlaps the given point, if any.
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user