Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 10 additions & 23 deletions src/inclusive_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,14 @@ where
/// any existing range _mapping to the same value_, then the ranges
/// will be coalesced into a single contiguous range.
///
/// # Panics
///
/// Panics if range `start > end`.
/// Inserting an empty range is a no-op.
pub fn insert(&mut self, range: RangeInclusive<K>, value: V) {
use core::ops::Bound;

// Backwards ranges don't make sense.
// `RangeInclusive` doesn't enforce this,
// and we don't want weird explosions further down
// if someone gives us such a range.
assert!(
range.start() <= range.end(),
"Range start can not be after range end"
);
// Inserting an empty range is a no-op.
if range.is_empty() {
return;
}

// Wrap up the given range so that we can "borrow"
// it as a wrapper reference to either its start or end.
Expand Down Expand Up @@ -374,21 +368,14 @@ where
/// in the map, then those ranges will be contracted to no
/// longer cover the removed range.
///
///
/// # Panics
///
/// Panics if range `start > end`.
/// Removing an empty range is a no-op.
pub fn remove(&mut self, range: RangeInclusive<K>) {
use core::ops::Bound;

// Backwards ranges don't make sense.
// `RangeInclusive` doesn't enforce this,
// and we don't want weird explosions further down
// if someone gives us such a range.
assert!(
range.start() <= range.end(),
"Range start can not be after range end"
);
// Removing an empty range is a no-op.
if range.is_empty() {
return;
}

let range_start_wrapper: RangeInclusiveStartWrapper<K> =
RangeInclusiveStartWrapper::new(range);
Expand Down
8 changes: 2 additions & 6 deletions src/inclusive_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ where
/// any existing range, then the ranges will be coalesced into
/// a single contiguous range.
///
/// # Panics
///
/// Panics if range `start > end`.
/// Inserting an empty range is a no-op.
pub fn insert(&mut self, range: RangeInclusive<T>) {
self.rm.insert(range, ());
}
Expand All @@ -153,9 +151,7 @@ where
/// in the set, then those ranges will be contracted to no
/// longer cover the removed range.
///
/// # Panics
///
/// Panics if range `start > end`.
/// Removing an empty range is a no-op.
pub fn remove(&mut self, range: RangeInclusive<T>) {
self.rm.remove(range);
}
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ for (range, person) in roster.iter() {
// 2019-03-04UTC (P7D): Carol
```

## Empty ranges

Insert and remove operations in this crate change a subset of the data structure,
defined by the passed range. When the passed range is empty, the operation
results in a no-op, similar to adding 0 to a number.

## Crate features

Expand Down
23 changes: 10 additions & 13 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,12 @@ where
/// any existing range _mapping to the same value_, then the ranges
/// will be coalesced into a single contiguous range.
///
/// # Panics
///
/// Panics if range `start >= end`.
/// Inserting an empty range is a no-op.
pub fn insert(&mut self, range: Range<K>, value: V) {
// We don't want to have to make empty ranges make sense;
// they don't represent anything meaningful in this structure.
assert!(range.start < range.end);
// Inserting an empty range is a no-op.
if range.is_empty() {
return;
}

// Wrap up the given range so that we can "borrow"
// it as a wrapper reference to either its start or end.
Expand Down Expand Up @@ -368,14 +367,12 @@ where
/// in the map, then those ranges will be contracted to no
/// longer cover the removed range.
///
///
/// # Panics
///
/// Panics if range `start >= end`.
/// Removing an empty range is a no-op.
pub fn remove(&mut self, range: Range<K>) {
// We don't want to have to make empty ranges make sense;
// they don't represent anything meaningful in this structure.
assert!(range.start < range.end);
// Removing an empty range is a no-op.
if range.is_empty() {
return;
}

let start_wrapper: RangeStartWrapper<K> = RangeStartWrapper::new(range);
let range = &start_wrapper.end_wrapper.range;
Expand Down
8 changes: 2 additions & 6 deletions src/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ where
/// any existing range, then the ranges will be coalesced into
/// a single contiguous range.
///
/// # Panics
///
/// Panics if range `start >= end`.
/// Inserting an empty range is a no-op.
pub fn insert(&mut self, range: Range<T>) {
self.rm.insert(range, ());
}
Expand All @@ -133,9 +131,7 @@ where
/// in the set, then those ranges will be contracted to no
/// longer cover the removed range.
///
/// # Panics
///
/// Panics if range `start >= end`.
/// Removing an empty range is a no-op.
pub fn remove(&mut self, range: Range<T>) {
self.rm.remove(range);
}
Expand Down