Merge pull request #14 from ripytide/rename_insert_platonic_to_insert_strict

Rename `insert_platonic` to `insert_strict`
This commit is contained in:
ripytide
2023-03-31 16:47:34 +01:00
committed by GitHub
7 changed files with 60 additions and 60 deletions
+2 -2
View File
@@ -24,8 +24,8 @@ use range_bounds_map::RangeBoundsMap;
let mut range_bounds_map = RangeBoundsMap::new();
range_bounds_map.insert_platonic(0..5, true);
range_bounds_map.insert_platonic(5..10, false);
range_bounds_map.insert_strict(0..5, true);
range_bounds_map.insert_strict(5..10, false);
assert_eq!(range_bounds_map.overlaps(&(-2..12)), true);
assert_eq!(range_bounds_map.contains_point(&20), false);
+2 -2
View File
@@ -10,12 +10,12 @@ use range_bounds_map::*;
const REPEAT: usize = 120;
#[bench]
fn bench_insert_platonic(b: &mut Bencher) {
fn bench_insert_strict(b: &mut Bencher) {
b.iter(|| {
let mut map = RangeBoundsMap::new();
for i in 0..REPEAT {
let r = i..=i;
map.insert_platonic(r, i).expect("insert failed");
map.insert_strict(r, i).expect("insert failed");
}
});
}
+1 -1
View File
@@ -15,7 +15,7 @@ const REPEAT: usize = 120;
fn build_identity_map(n: usize) -> RangeBoundsMap<usize, Range<usize>, usize> {
let mut map = RangeBoundsMap::new();
for i in 0..n {
map.insert_platonic(i..i + 1, i).expect("insert failed");
map.insert_strict(i..i + 1, i).expect("insert failed");
}
map
}
+2 -2
View File
@@ -32,8 +32,8 @@ along with range_bounds_map. If not, see <https://www.gnu.org/licenses/>.
//!
//! let mut range_bounds_map = RangeBoundsMap::new();
//!
//! range_bounds_map.insert_platonic(0..5, true);
//! range_bounds_map.insert_platonic(5..10, false);
//! range_bounds_map.insert_strict(0..5, true);
//! range_bounds_map.insert_strict(5..10, false);
//!
//! assert_eq!(range_bounds_map.overlaps(&(-2..12)), true);
//! assert_eq!(range_bounds_map.contains_point(&20), false);
+34 -34
View File
@@ -107,8 +107,8 @@ use crate::TryFromBounds;
/// // Now we can make a [`RangeBoundsMap`] of [`ExEx`]s to `u8`
/// let mut map = RangeBoundsMap::new();
///
/// map.insert_platonic(ExEx::new(0.0, 5.0), 8).unwrap();
/// map.insert_platonic(ExEx::new(5.0, 7.5), 32).unwrap();
/// map.insert_strict(ExEx::new(0.0, 5.0), 8).unwrap();
/// map.insert_strict(ExEx::new(5.0, 7.5), 32).unwrap();
///
/// assert_eq!(map.contains_point(&NotNan::new(5.0).unwrap()), false);
///
@@ -304,7 +304,7 @@ where
/// let mut range_bounds_map = RangeBoundsMap::new();
///
/// assert_eq!(range_bounds_map.len(), 0);
/// range_bounds_map.insert_platonic(0..1, false).unwrap();
/// range_bounds_map.insert_strict(0..1, false).unwrap();
/// assert_eq!(range_bounds_map.len(), 1);
/// ```
#[trivial]
@@ -322,7 +322,7 @@ where
/// let mut range_bounds_map = RangeBoundsMap::new();
///
/// assert_eq!(range_bounds_map.is_empty(), true);
/// range_bounds_map.insert_platonic(0..1, false).unwrap();
/// range_bounds_map.insert_strict(0..1, false).unwrap();
/// assert_eq!(range_bounds_map.is_empty(), false);
/// ```
#[trivial]
@@ -343,15 +343,15 @@ where
///
/// let mut range_bounds_map = RangeBoundsMap::new();
///
/// assert_eq!(range_bounds_map.insert_platonic(5..10, 9), Ok(()));
/// assert_eq!(range_bounds_map.insert_strict(5..10, 9), Ok(()));
/// assert_eq!(
/// range_bounds_map.insert_platonic(5..10, 2),
/// range_bounds_map.insert_strict(5..10, 2),
/// Err(OverlapError)
/// );
/// assert_eq!(range_bounds_map.len(), 1);
/// ```
#[tested]
pub fn insert_platonic(
pub fn insert_strict(
&mut self,
range_bounds: K,
value: V,
@@ -384,7 +384,7 @@ where
///
/// let mut range_bounds_map = RangeBoundsMap::new();
///
/// range_bounds_map.insert_platonic(5..10, false);
/// range_bounds_map.insert_strict(5..10, false);
///
/// assert_eq!(range_bounds_map.overlaps(&(1..=3)), false);
/// assert_eq!(range_bounds_map.overlaps(&(4..5)), false);
@@ -764,7 +764,7 @@ where
if to_insert.iter().all(|(x, _)| K::is_valid(x)) {
let mut removed = self.remove_overlapping(range_bounds);
for ((start, end), value) in to_insert.into_iter() {
self.insert_platonic(
self.insert_strict(
K::try_from_bounds(start, end).unwrap(),
value,
)
@@ -1327,7 +1327,7 @@ where
/// `RangeBounds`.
///
/// This is equivalent to using [`RangeBoundsMap::cut()`]
/// followed by [`RangeBoundsMap::insert_platonic()`]. Hence the
/// followed by [`RangeBoundsMap::insert_strict()`]. Hence the
/// same `V: Clone` trait bound applies.
///
/// If the remaining `RangeBounds` left after the cut are not able
@@ -1359,7 +1359,7 @@ where
K: TryFromBounds<I>,
{
let _ = self.cut(&range_bounds)?;
self.insert_platonic(range_bounds, value).unwrap();
self.insert_strict(range_bounds, value).unwrap();
return Ok(());
}
@@ -1412,7 +1412,7 @@ where
}
/// Moves all elements from `other` into `self` by
/// [`RangeBoundsMap::insert_platonic()`] in ascending order,
/// [`RangeBoundsMap::insert_strict()`] in ascending order,
/// leaving `other` empty.
///
/// If any of the `RangeBounds` in `other` overlap `self` then
@@ -1440,19 +1440,19 @@ where
/// ])
/// .unwrap();
///
/// assert_eq!(base.append_platonic(&mut add), Ok(()));
/// assert_eq!(base.append_strict(&mut add), Ok(()));
/// assert_eq!(base, expected);
/// assert!(add.is_empty());
/// ```
#[trivial]
pub fn append_platonic(
pub fn append_strict(
&mut self,
other: &mut RangeBoundsMap<I, K, V>,
) -> Result<(), OverlapError> {
for (range_bounds, value) in
other.remove_overlapping(&(Bound::Unbounded::<I>, Bound::Unbounded))
{
self.insert_platonic(range_bounds, value)?;
self.insert_strict(range_bounds, value)?;
}
return Ok(());
@@ -1518,7 +1518,7 @@ where
for (possible_key, value) in split_off {
match possible_key {
Ok(key) => output.insert_platonic(key, value).unwrap(),
Ok(key) => output.insert_strict(key, value).unwrap(),
Err(TryFromBoundsError) => {
*self = before;
return Err(TryFromBoundsError);
@@ -1646,7 +1646,7 @@ where
fn try_from(pairs: [(K, V); N]) -> Result<Self, Self::Error> {
let mut range_bounds_map = RangeBoundsMap::new();
for (range_bounds, value) in pairs {
range_bounds_map.insert_platonic(range_bounds, value)?;
range_bounds_map.insert_strict(range_bounds, value)?;
}
return Ok(range_bounds_map);
@@ -1662,7 +1662,7 @@ where
fn try_from(pairs: Vec<(K, V)>) -> Result<Self, Self::Error> {
let mut range_bounds_map = RangeBoundsMap::new();
for (range_bounds, value) in pairs {
range_bounds_map.insert_platonic(range_bounds, value)?;
range_bounds_map.insert_strict(range_bounds, value)?;
}
return Ok(range_bounds_map);
@@ -1679,7 +1679,7 @@ where
let mut output = RangeBoundsMap::new();
for (range_bounds, value) in iter {
output.insert_platonic(range_bounds, value).unwrap();
output.insert_strict(range_bounds, value).unwrap();
}
return output;
@@ -1796,7 +1796,7 @@ where
let mut range_bounds_map = RangeBoundsMap::new();
while let Some((range_bounds, value)) = access.next_entry()? {
range_bounds_map
.insert_platonic(range_bounds, value)
.insert_strict(range_bounds, value)
.map_err(|_| serde::de::Error::custom("RangeBounds overlap"))?;
}
Ok(range_bounds_map)
@@ -2130,20 +2130,20 @@ mod tests {
}
#[test]
fn insert_platonic_tests() {
assert_insert_platonic(
fn insert_strict_tests() {
assert_insert_strict(
basic(),
(ii(0, 4), false),
Err(OverlapError),
None::<[_; 0]>,
);
assert_insert_platonic(
assert_insert_strict(
basic(),
(ii(5, 6), false),
Err(OverlapError),
None::<[_; 0]>,
);
assert_insert_platonic(
assert_insert_strict(
basic(),
(ee(7, 8), false),
Ok(()),
@@ -2155,13 +2155,13 @@ mod tests {
(ie(14, 16), true),
]),
);
assert_insert_platonic(
assert_insert_strict(
basic(),
(ii(4, 5), true),
Err(OverlapError),
None::<[_; 0]>,
);
assert_insert_platonic(
assert_insert_strict(
basic(),
(ei(4, 5), true),
Ok(()),
@@ -2174,14 +2174,14 @@ mod tests {
]),
);
}
fn assert_insert_platonic<const N: usize>(
fn assert_insert_strict<const N: usize>(
mut before: RangeBoundsMap<u8, TestBounds, bool>,
to_insert: (TestBounds, bool),
result: Result<(), OverlapError>,
after: Option<[(TestBounds, bool); N]>,
) {
let clone = before.clone();
assert_eq!(before.insert_platonic(to_insert.0, to_insert.1), result);
assert_eq!(before.insert_strict(to_insert.0, to_insert.1), result);
match after {
Some(after) => {
assert_eq!(before, RangeBoundsMap::try_from(after).unwrap())
@@ -2207,7 +2207,7 @@ mod tests {
for overlap_range in all_valid_test_bounds() {
for inside_range in all_valid_test_bounds() {
let mut range_bounds_map = RangeBoundsMap::new();
range_bounds_map.insert_platonic(inside_range, ()).unwrap();
range_bounds_map.insert_strict(inside_range, ()).unwrap();
let mut expected_overlapping = Vec::new();
if overlaps(&overlap_range, &inside_range) {
@@ -2236,8 +2236,8 @@ mod tests {
all_non_overlapping_test_bound_pairs()
{
let mut range_bounds_map = RangeBoundsMap::new();
range_bounds_map.insert_platonic(inside_range1, ()).unwrap();
range_bounds_map.insert_platonic(inside_range2, ()).unwrap();
range_bounds_map.insert_strict(inside_range1, ()).unwrap();
range_bounds_map.insert_strict(inside_range2, ()).unwrap();
let mut expected_overlapping = Vec::new();
if overlaps(&overlap_range, &inside_range1) {
@@ -2289,7 +2289,7 @@ mod tests {
for overlap_range in all_valid_test_bounds() {
for inside_range in all_valid_test_bounds() {
let mut range_bounds_map = RangeBoundsMap::new();
range_bounds_map.insert_platonic(inside_range, ()).unwrap();
range_bounds_map.insert_strict(inside_range, ()).unwrap();
let result = range_bounds_map
.overlapping_trimmed(&overlap_range)
@@ -2311,8 +2311,8 @@ mod tests {
all_non_overlapping_test_bound_pairs()
{
let mut range_bounds_map = RangeBoundsMap::new();
range_bounds_map.insert_platonic(inside_range1, ()).unwrap();
range_bounds_map.insert_platonic(inside_range2, ()).unwrap();
range_bounds_map.insert_strict(inside_range1, ()).unwrap();
range_bounds_map.insert_strict(inside_range2, ()).unwrap();
let result = range_bounds_map
.overlapping_trimmed(&overlap_range)
+18 -18
View File
@@ -95,8 +95,8 @@ use crate::{
/// // Now we can make a [`RangeBoundsSet`] of [`ExEx`]s
/// let mut set = RangeBoundsSet::new();
///
/// set.insert_platonic(ExEx::new(0.0, 5.0)).unwrap();
/// set.insert_platonic(ExEx::new(5.0, 7.5)).unwrap();
/// set.insert_strict(ExEx::new(0.0, 5.0)).unwrap();
/// set.insert_strict(ExEx::new(5.0, 7.5)).unwrap();
///
/// assert_eq!(set.contains_point(&NotNan::new(5.0).unwrap()), false);
///
@@ -148,7 +148,7 @@ where
/// let mut range_bounds_set = RangeBoundsSet::new();
///
/// assert_eq!(range_bounds_set.len(), 0);
/// range_bounds_set.insert_platonic(0..1).unwrap();
/// range_bounds_set.insert_strict(0..1).unwrap();
/// assert_eq!(range_bounds_set.len(), 1);
/// ```
#[trivial]
@@ -166,7 +166,7 @@ where
/// let mut range_bounds_set = RangeBoundsSet::new();
///
/// assert_eq!(range_bounds_set.is_empty(), true);
/// range_bounds_set.insert_platonic(0..1).unwrap();
/// range_bounds_set.insert_strict(0..1).unwrap();
/// assert_eq!(range_bounds_set.is_empty(), false);
/// ```
#[trivial]
@@ -187,19 +187,19 @@ where
///
/// let mut range_bounds_set = RangeBoundsSet::new();
///
/// assert_eq!(range_bounds_set.insert_platonic(5..10), Ok(()));
/// assert_eq!(range_bounds_set.insert_strict(5..10), Ok(()));
/// assert_eq!(
/// range_bounds_set.insert_platonic(5..10),
/// range_bounds_set.insert_strict(5..10),
/// Err(OverlapError)
/// );
/// assert_eq!(range_bounds_set.len(), 1);
/// ```
#[trivial]
pub fn insert_platonic(
pub fn insert_strict(
&mut self,
range_bounds: K,
) -> Result<(), OverlapError> {
self.map.insert_platonic(range_bounds, ())
self.map.insert_strict(range_bounds, ())
}
/// Returns `true` if the given `RangeBounds` overlaps any of the
@@ -211,7 +211,7 @@ where
///
/// let mut range_bounds_set = RangeBoundsSet::new();
///
/// range_bounds_set.insert_platonic(5..10);
/// range_bounds_set.insert_strict(5..10);
///
/// assert_eq!(range_bounds_set.overlaps(&(1..=3)), false);
/// assert_eq!(range_bounds_set.overlaps(&(4..5)), false);
@@ -692,7 +692,7 @@ where
/// `RangeBounds` that overlap the new `RangeBounds`.
///
/// This is equivalent to using [`RangeBoundsSet::cut()`]
/// followed by [`RangeBoundsSet::insert_platonic()`].
/// followed by [`RangeBoundsSet::insert_strict()`].
///
/// If the remaining `RangeBounds` left after the cut are not able
/// to be created with the [`TryFromBounds`] trait then a
@@ -756,7 +756,7 @@ where
}
/// Moves all elements from `other` into `self` by
/// [`RangeBoundsSet::insert_platonic()`] in acending order,
/// [`RangeBoundsSet::insert_strict()`] in acending order,
/// leaving `other` empty.
///
/// If any of the `RangeBounds` in `other` overlap `self` then
@@ -776,16 +776,16 @@ where
/// RangeBoundsSet::try_from([1..4, 4..8, 10..38, 40..42])
/// .unwrap();
///
/// assert_eq!(base.append_platonic(&mut add), Ok(()));
/// assert_eq!(base.append_strict(&mut add), Ok(()));
/// assert_eq!(base, expected);
/// assert!(add.is_empty());
/// ```
#[trivial]
pub fn append_platonic(
pub fn append_strict(
&mut self,
other: &mut RangeBoundsSet<I, K>,
) -> Result<(), OverlapError> {
self.map.append_platonic(
self.map.append_strict(
&mut other
.remove_overlapping(&(Bound::Unbounded::<I>, Bound::Unbounded))
.map(|key| (key, ()))
@@ -921,7 +921,7 @@ where
fn try_from(pairs: [K; N]) -> Result<Self, Self::Error> {
let mut range_bounds_set = RangeBoundsSet::new();
for range_bounds in pairs {
range_bounds_set.insert_platonic(range_bounds)?;
range_bounds_set.insert_strict(range_bounds)?;
}
return Ok(range_bounds_set);
@@ -937,7 +937,7 @@ where
fn try_from(pairs: Vec<K>) -> Result<Self, Self::Error> {
let mut range_bounds_set = RangeBoundsSet::new();
for range_bounds in pairs {
range_bounds_set.insert_platonic(range_bounds)?;
range_bounds_set.insert_strict(range_bounds)?;
}
return Ok(range_bounds_set);
@@ -954,7 +954,7 @@ where
let mut output = RangeBoundsSet::new();
for range_bounds in iter {
output.insert_platonic(range_bounds).unwrap();
output.insert_strict(range_bounds).unwrap();
}
return output;
@@ -1065,7 +1065,7 @@ where
let mut range_bounds_set = RangeBoundsSet::new();
while let Some(range_bounds) = access.next_element()? {
range_bounds_set
.insert_platonic(range_bounds)
.insert_strict(range_bounds)
.map_err(|_| serde::de::Error::custom("RangeBounds overlap"))?;
}
Ok(range_bounds_set)
+1 -1
View File
@@ -38,7 +38,7 @@
# open questions
- should we implement FromIterator? If so which insert should we use?
(At the moment we do implement it using insert_platonic())
(At the moment we do implement it using insert_strict())
- should append\_\* functions not change the base if they fail half way?
#### PUBLISH