fixed clippy and added is_empty() to map and set

This commit is contained in:
ripytide
2022-12-12 00:50:53 +00:00
parent c3c61c4134
commit 4f104c8c11
2 changed files with 41 additions and 12 deletions
+22 -11
View File
@@ -308,6 +308,24 @@ where
self.starts.len()
}
/// Returns `true` if the map contains no `RangeBounds`, and
/// `false` if it does.
///
/// # Examples
/// ```
/// use range_bounds_map::RangeBoundsMap;
///
/// let mut range_bounds_map = RangeBoundsMap::new();
///
/// assert_eq!(range_bounds_map.is_empty(), true);
/// range_bounds_map.insert_platonic(0..1, false).unwrap();
/// assert_eq!(range_bounds_map.is_empty(), false);
/// ```
#[trivial]
pub fn is_empty(&self) -> bool {
self.len() == 0
}
/// Adds a new (`RangeBounds`, `Value`) pair to the map without
/// modifying other entries.
///
@@ -354,7 +372,7 @@ where
}
/// Returns `true` if the given `RangeBounds` overlaps any of the
/// `RangeBounds` in the map.
/// `RangeBounds` in the map, and `false` if not.
///
/// # Examples
/// ```
@@ -1275,15 +1293,11 @@ where
{
let overlapping_swell = self.overlapping_swell(&range_bounds);
let start_bound = match self.touching_left(&range_bounds) {
Some(touching_left) => {
Bound::from(touching_left.start_bound().cloned())
}
Some(touching_left) => touching_left.start_bound().cloned(),
None => overlapping_swell.0.cloned(),
};
let end_bound = match self.touching_right(&range_bounds) {
Some(touching_right) => {
Bound::from(touching_right.end_bound().cloned())
}
Some(touching_right) => touching_right.end_bound().cloned(),
None => overlapping_swell.1.cloned(),
};
@@ -1624,10 +1638,7 @@ where
B: RangeBounds<I>,
I: PartialOrd,
{
match sorted_config(a, b) {
SortedConfig::NonOverlapping(_, _) => false,
_ => true,
}
!matches!(sorted_config(a, b), SortedConfig::NonOverlapping(_, _))
}
#[rustfmt::skip]
+19 -1
View File
@@ -152,6 +152,24 @@ where
self.map.len()
}
/// Returns `true` if the set contains no `RangeBounds`, and
/// `false` if it does.
///
/// # Examples
/// ```
/// use range_bounds_map::RangeBoundsSet;
///
/// let mut range_bounds_set = RangeBoundsSet::new();
///
/// assert_eq!(range_bounds_set.is_empty(), true);
/// range_bounds_set.insert_platonic(0..1).unwrap();
/// assert_eq!(range_bounds_set.is_empty(), false);
/// ```
#[trivial]
pub fn is_empty(&self) -> bool {
self.len() == 0
}
/// Adds a new `RangeBounds` to the set without modifying other
/// `RangeBounds` in the set.
///
@@ -181,7 +199,7 @@ where
}
/// Returns `true` if the given `RangeBounds` overlaps any of the
/// `RangeBounds` in the set.
/// `RangeBounds` in the set, and `false` if not.
///
/// # Examples
/// ```