From 3b61cf1747fa39bcb534d49077badc4ed5f8abd9 Mon Sep 17 00:00:00 2001 From: ripytide Date: Fri, 21 Apr 2023 12:45:16 +0100 Subject: [PATCH] renamed finite_bounds to discretefinitebounds --- ...te_bounds.rs => discrete_finite_bounds.rs} | 6 +- src/lib.rs | 4 +- src/range_bounds_map.rs | 158 +++++++++--------- src/range_bounds_set.rs | 18 +- src/test_ranges.rs | 34 ++-- src/utils.rs | 38 ++--- 6 files changed, 129 insertions(+), 129 deletions(-) rename src/{discrete_bounds.rs => discrete_finite_bounds.rs} (89%) diff --git a/src/discrete_bounds.rs b/src/discrete_finite_bounds.rs similarity index 89% rename from src/discrete_bounds.rs rename to src/discrete_finite_bounds.rs index dba2ef4..a9db405 100644 --- a/src/discrete_bounds.rs +++ b/src/discrete_finite_bounds.rs @@ -22,13 +22,13 @@ use std::ops::{Bound, RangeBounds}; use crate::range_bounds_map::FiniteRange; #[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub struct FiniteBounds { +pub struct DiscreteFiniteBounds { //both are always included pub start: I, pub end: I, } -impl RangeBounds for FiniteBounds { +impl RangeBounds for DiscreteFiniteBounds { fn start_bound(&self) -> Bound<&I> { Bound::Included(&self.start) } @@ -37,7 +37,7 @@ impl RangeBounds for FiniteBounds { } } -impl FiniteRange for FiniteBounds +impl FiniteRange for DiscreteFiniteBounds where I: Copy, { diff --git a/src/lib.rs b/src/lib.rs index 4dd45ec..46d39da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -220,13 +220,13 @@ along with range_bounds_map. If not, see . pub mod test_ranges; pub(crate) mod utils; -pub mod discrete_bounds; +pub mod discrete_finite_bounds; pub mod discrete_finite; pub mod range_bounds_map; pub mod range_bounds_set; -pub use crate::discrete_bounds::FiniteBounds; +pub use crate::discrete_finite_bounds::DiscreteFiniteBounds; pub use crate::discrete_finite::DiscreteFinite; pub use crate::range_bounds_map::{OverlapError, RangeBoundsMap}; pub use crate::range_bounds_set::RangeBoundsSet; diff --git a/src/range_bounds_map.rs b/src/range_bounds_map.rs index d0021cb..282a76e 100644 --- a/src/range_bounds_map.rs +++ b/src/range_bounds_map.rs @@ -29,7 +29,7 @@ use serde::de::{MapAccess, Visitor}; use serde::ser::SerializeMap; use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use crate::discrete_bounds::FiniteBounds; +use crate::discrete_finite_bounds::DiscreteFiniteBounds; use crate::discrete_finite::DiscreteFinite; use crate::utils::{cmp_point_with_range, cut_range, is_valid_range, overlaps}; @@ -149,9 +149,9 @@ where /// use std::ops::Range; /// /// use range_bounds_map::RangeBoundsMap; - /// use range_bounds_map::DiscreteBounds; + /// use range_bounds_map::DiscreteFiniteBounds; /// - /// let map: RangeBoundsMap, bool> = + /// let map: RangeBoundsMap, bool> = /// RangeBoundsMap::new(); /// ``` pub fn new() -> Self { @@ -416,12 +416,12 @@ where /// Err(iu(100)) /// ); /// ``` - pub fn get_entry_at_point(&self, point: I) -> Result<(&K, &V), FiniteBounds> { + pub fn get_entry_at_point(&self, point: I) -> Result<(&K, &V), DiscreteFiniteBounds> { self.inner .get_key_value(overlapping_comp(point)) .ok_or_else(|| self.get_gap_at_raw(point)) } - fn get_gap_at_raw(&self, point: I) -> FiniteBounds { + fn get_gap_at_raw(&self, point: I) -> DiscreteFiniteBounds { let lower = self .inner .upper_bound(overlapping_comp(point), SearchBoundCustom::Included); @@ -429,7 +429,7 @@ where .inner .lower_bound(overlapping_comp(point), SearchBoundCustom::Included); - FiniteBounds { + DiscreteFiniteBounds { start: lower .key() .map_or(I::MIN, |lower| lower.end().up().unwrap()), @@ -542,8 +542,8 @@ where /// the full or partial ranges that were cut. /// /// If the remaining ranges left in the map after the cut would - /// not be able be created with the [`TryFromDiscreteBounds`] trait then a - /// [`TryFromDiscreteBoundsError`] will be returned and the map will not + /// not be able be created with the [`TryFromDiscreteFiniteBounds`] trait then a + /// [`TryFromDiscreteFiniteBoundsError`] will be returned and the map will not /// be cut at all. /// /// `V` must implement `Clone` as if you try to cut out the center @@ -562,7 +562,7 @@ where /// use std::ops::Bound; /// /// use range_bounds_map::test_ranges::{ie, ie_strict, ii}; - /// use range_bounds_map::{RangeBoundsMap, TryFromDiscreteBoundsError}; + /// use range_bounds_map::{RangeBoundsMap, TryFromDiscreteFiniteBoundsError}; /// /// let mut base = RangeBoundsMap::from_slice_strict([ /// (ie_strict(1, 4), false), @@ -587,10 +587,10 @@ where /// ); /// assert_eq!(base, after_cut); /// ``` - pub fn cut<'a, Q>(&'a mut self, range: Q) -> impl Iterator, V)> + '_ + pub fn cut<'a, Q>(&'a mut self, range: Q) -> impl Iterator, V)> + '_ where Q: FiniteRange + Copy + 'a, - K: From>, + K: From>, V: Clone, { invalid_range_panic(range); @@ -619,10 +619,10 @@ where &mut self, range: Q, single_overlapping_range: K, - ) -> impl Iterator, V)> + ) -> impl Iterator, V)> where Q: FiniteRange + Copy, - K: From>, + K: From>, V: Clone, { invalid_range_panic(range); @@ -648,10 +648,10 @@ where range: Q, left_overlapping: Option, right_overlapping: Option, - ) -> impl Iterator, V)> + '_ + ) -> impl Iterator, V)> + '_ where Q: FiniteRange + Copy + 'a, - K: From>, + K: From>, V: Clone, { invalid_range_panic(range); @@ -695,7 +695,7 @@ where .into_iter() .chain(self.remove_overlapping(range).map(|(key, value)| { ( - FiniteBounds { + DiscreteFiniteBounds { start: key.start(), end: key.end(), }, @@ -740,7 +740,7 @@ where /// ] /// ); /// ``` - pub fn gaps(&self, outer_range: Q) -> impl DoubleEndedIterator> + pub fn gaps(&self, outer_range: Q) -> impl DoubleEndedIterator> where Q: FiniteRange + Copy, { @@ -794,7 +794,7 @@ where //find one at the time of writing .collect::>() .windows(2) - .map(|windows| FiniteBounds { + .map(|windows| DiscreteFiniteBounds { start: windows[0].1.up().unwrap(), end: windows[1].0.down().unwrap(), }) @@ -893,7 +893,7 @@ where remove_end: R2, ) -> K where - K: From>, + K: From>, G1: FnOnce(&Self, &V) -> Option, G2: FnOnce(&Self, &V) -> Option, R1: FnOnce(&mut Self, &V), @@ -905,15 +905,15 @@ where let matching_end = get_end(self, &value); let returning = match (matching_start, matching_end) { - (Some(matching_start), Some(matching_end)) => K::from(FiniteBounds { + (Some(matching_start), Some(matching_end)) => K::from(DiscreteFiniteBounds { start: matching_start.start(), end: matching_end.end(), }), - (Some(matching_start), None) => K::from(FiniteBounds { + (Some(matching_start), None) => K::from(DiscreteFiniteBounds { start: matching_start.start(), end: range.end(), }), - (None, Some(matching_end)) => K::from(FiniteBounds { + (None, Some(matching_end)) => K::from(DiscreteFiniteBounds { start: range.start(), end: matching_end.end(), }), @@ -945,7 +945,7 @@ where /// /// If the range merges with one or two touching ranges and the /// merged-together range cannot be created with the - /// [`TryFromDiscreteBounds`] trait then a [`TryFromDiscreteBoundsError`] will be + /// [`TryFromDiscreteFiniteBounds`] trait then a [`TryFromDiscreteFiniteBoundsError`] will be /// returned. /// /// # Panics @@ -958,7 +958,7 @@ where /// ``` /// use range_bounds_map::test_ranges::ie; /// use range_bounds_map::{ - /// OverlapError, OverlapOrTryFromDiscreteBoundsError, RangeBoundsMap, + /// OverlapError, OverlapOrTryFromDiscreteFiniteBoundsError, RangeBoundsMap, /// }; /// /// let mut map = RangeBoundsMap::from_slice_strict([ @@ -976,7 +976,7 @@ where /// // Overlapping /// assert_eq!( /// map.insert_merge_touching(ie(4, 8), false), - /// Err(OverlapOrTryFromDiscreteBoundsError::Overlap(OverlapError)), + /// Err(OverlapOrTryFromDiscreteFiniteBoundsError::Overlap(OverlapError)), /// ); /// /// // Neither Touching or Overlapping @@ -992,7 +992,7 @@ where /// ``` pub fn insert_merge_touching(&mut self, range: K, value: V) -> Result where - K: From>, + K: From>, { invalid_range_panic(range); @@ -1039,7 +1039,7 @@ where /// /// If the range merges with one or two touching ranges and the /// merged-together range cannot be created with the - /// [`TryFromDiscreteBounds`] trait then a [`TryFromDiscreteBoundsError`] will be + /// [`TryFromDiscreteFiniteBounds`] trait then a [`TryFromDiscreteFiniteBoundsError`] will be /// returned. /// /// # Panics @@ -1052,7 +1052,7 @@ where /// ``` /// use range_bounds_map::test_ranges::ie; /// use range_bounds_map::{ - /// OverlapError, OverlapOrTryFromDiscreteBoundsError, RangeBoundsMap, + /// OverlapError, OverlapOrTryFromDiscreteFiniteBoundsError, RangeBoundsMap, /// }; /// /// let mut map = RangeBoundsMap::from_slice_strict([ @@ -1070,7 +1070,7 @@ where /// // Overlapping /// assert_eq!( /// map.insert_merge_touching_if_values_equal(ie(4, 8), false), - /// Err(OverlapOrTryFromDiscreteBoundsError::Overlap(OverlapError)), + /// Err(OverlapOrTryFromDiscreteFiniteBoundsError::Overlap(OverlapError)), /// ); /// /// // Neither Touching or Overlapping @@ -1090,7 +1090,7 @@ where value: V, ) -> Result where - K: From>, + K: From>, V: Eq, { invalid_range_panic(range); @@ -1144,8 +1144,8 @@ where /// returned. /// /// If the range merges other ranges and the merged-together range - /// cannot be created with the [`TryFromDiscreteBounds`] trait then a - /// [`TryFromDiscreteBoundsError`] will be returned. + /// cannot be created with the [`TryFromDiscreteFiniteBounds`] trait then a + /// [`TryFromDiscreteFiniteBoundsError`] will be returned. /// /// # Panics /// @@ -1157,7 +1157,7 @@ where /// ``` /// use range_bounds_map::test_ranges::ie; /// use range_bounds_map::{ - /// OverlapError, OverlapOrTryFromDiscreteBoundsError, RangeBoundsMap, + /// OverlapError, OverlapOrTryFromDiscreteFiniteBoundsError, RangeBoundsMap, /// }; /// /// let mut map = RangeBoundsMap::from_slice_strict([ @@ -1191,7 +1191,7 @@ where /// ``` pub fn insert_merge_overlapping(&mut self, range: K, value: V) -> K where - K: From>, + K: From>, { invalid_range_panic(range); @@ -1227,8 +1227,8 @@ where /// returned. /// /// If the range merges other ranges and the merged-together range - /// cannot be created with the [`TryFromDiscreteBounds`] trait then a - /// [`TryFromDiscreteBoundsError`] will be returned. + /// cannot be created with the [`TryFromDiscreteFiniteBounds`] trait then a + /// [`TryFromDiscreteFiniteBoundsError`] will be returned. /// /// # Panics /// @@ -1240,7 +1240,7 @@ where /// ``` /// use range_bounds_map::test_ranges::ie; /// use range_bounds_map::{ - /// OverlapError, OverlapOrTryFromDiscreteBoundsError, RangeBoundsMap, + /// OverlapError, OverlapOrTryFromDiscreteFiniteBoundsError, RangeBoundsMap, /// }; /// /// let mut map = RangeBoundsMap::from_slice_strict([ @@ -1274,7 +1274,7 @@ where /// ``` pub fn insert_merge_touching_or_overlapping(&mut self, range: K, value: V) -> K where - K: From>, + K: From>, { invalid_range_panic(range); @@ -1320,8 +1320,8 @@ where /// same `V: Clone` trait bound applies. /// /// If the remaining ranges left after the cut are not able to be - /// created with the [`TryFromDiscreteBounds`] trait then a - /// [`TryFromDiscreteBoundsError`] will be returned. + /// created with the [`TryFromDiscreteFiniteBounds`] trait then a + /// [`TryFromDiscreteFiniteBoundsError`] will be returned. /// /// # Panics /// @@ -1347,7 +1347,7 @@ where /// ``` pub fn insert_overwrite(&mut self, range: K, value: V) where - K: From>, + K: From>, V: Clone, { invalid_range_panic(range); @@ -1414,7 +1414,7 @@ where /// # Examples /// ``` /// use range_bounds_map::test_ranges::ie; - /// use range_bounds_map::{RangeBoundsMap, TryFromDiscreteBoundsError}; + /// use range_bounds_map::{RangeBoundsMap, TryFromDiscreteFiniteBoundsError}; /// /// let map = RangeBoundsMap::from_slice_strict([ /// (ie(1, 4), false), @@ -1612,7 +1612,7 @@ mod tests { //go a bit around on either side to compensate for Unbounded pub(crate) const NUMBERS_DOMAIN: &'static [i8] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; - fn basic() -> RangeBoundsMap, bool> { + fn basic() -> RangeBoundsMap, bool> { RangeBoundsMap::from_slice_strict([ (ui(4), false), (ee(5, 7), true), @@ -1621,7 +1621,7 @@ mod tests { ]) .unwrap() } - fn basic_slice() -> [(FiniteBounds, bool); 4] { + fn basic_slice() -> [(DiscreteFiniteBounds, bool); 4] { [ (ui(4), false), (ee(5, 7), true), @@ -1649,10 +1649,10 @@ mod tests { ); } fn assert_insert_strict( - mut before: RangeBoundsMap, bool>, - to_insert: (FiniteBounds, bool), + mut before: RangeBoundsMap, bool>, + to_insert: (DiscreteFiniteBounds, bool), result: Result<(), OverlapError>, - after: [(FiniteBounds, bool); N], + after: [(DiscreteFiniteBounds, bool); N], ) { assert_eq!(before.insert_strict(to_insert.0, to_insert.1), result); assert_eq!(before, RangeBoundsMap::from_slice_strict(after).unwrap()) @@ -1663,7 +1663,7 @@ mod tests { //case zero for overlap_range in all_valid_test_bounds() { //you can't overlap nothing - assert!(RangeBoundsMap::, ()>::new() + assert!(RangeBoundsMap::, ()>::new() .overlapping(overlap_range) .next() .is_none()); @@ -1758,10 +1758,10 @@ mod tests { ); } fn assert_remove_overlapping( - mut before: RangeBoundsMap, bool>, - to_remove: FiniteBounds, - result: [(FiniteBounds, bool); N], - after: [(FiniteBounds, bool); Y], + mut before: RangeBoundsMap, bool>, + to_remove: DiscreteFiniteBounds, + result: [(DiscreteFiniteBounds, bool); N], + after: [(DiscreteFiniteBounds, bool); Y], ) { assert_eq!( before.remove_overlapping(to_remove).collect::>(), @@ -1808,10 +1808,10 @@ mod tests { ); } fn assert_cut( - mut before: RangeBoundsMap, bool>, - to_cut: FiniteBounds, - result: [(FiniteBounds, bool); Y], - after: [(FiniteBounds, bool); N], + mut before: RangeBoundsMap, bool>, + to_cut: DiscreteFiniteBounds, + result: [(DiscreteFiniteBounds, bool); Y], + after: [(DiscreteFiniteBounds, bool); N], ) { assert_eq!(before.cut(to_cut).collect::>(), result); assert_eq!(before, RangeBoundsMap::from_slice_strict(after).unwrap()); @@ -1844,9 +1844,9 @@ mod tests { ); } fn assert_gaps( - map: RangeBoundsMap, bool>, - outer_range: FiniteBounds, - result: [FiniteBounds; N], + map: RangeBoundsMap, bool>, + outer_range: DiscreteFiniteBounds, + result: [DiscreteFiniteBounds; N], ) { assert_eq!(map.gaps(outer_range).collect::>(), result); } @@ -1894,10 +1894,10 @@ mod tests { ); } fn assert_insert_merge_touching( - mut before: RangeBoundsMap, bool>, - to_insert: (FiniteBounds, bool), - result: Result, OverlapError>, - after: [(FiniteBounds, bool); N], + mut before: RangeBoundsMap, bool>, + to_insert: (DiscreteFiniteBounds, bool), + result: Result, OverlapError>, + after: [(DiscreteFiniteBounds, bool); N], ) { assert_eq!( before.insert_merge_touching(to_insert.0, to_insert.1), @@ -1950,10 +1950,10 @@ mod tests { ); } fn assert_insert_merge_touching_if_values_equal( - mut before: RangeBoundsMap, bool>, - to_insert: (FiniteBounds, bool), - result: Result, OverlapError>, - after: [(FiniteBounds, bool); N], + mut before: RangeBoundsMap, bool>, + to_insert: (DiscreteFiniteBounds, bool), + result: Result, OverlapError>, + after: [(DiscreteFiniteBounds, bool); N], ) { assert_eq!( before.insert_merge_touching_if_values_equal(to_insert.0, to_insert.1), @@ -2006,10 +2006,10 @@ mod tests { assert_insert_merge_overlapping(basic(), (uu(), false), uu(), [(uu(), false)]); } fn assert_insert_merge_overlapping( - mut before: RangeBoundsMap, bool>, - to_insert: (FiniteBounds, bool), - result: FiniteBounds, - after: [(FiniteBounds, bool); N], + mut before: RangeBoundsMap, bool>, + to_insert: (DiscreteFiniteBounds, bool), + result: DiscreteFiniteBounds, + after: [(DiscreteFiniteBounds, bool); N], ) { assert_eq!( before.insert_merge_overlapping(to_insert.0, to_insert.1), @@ -2077,10 +2077,10 @@ mod tests { ); } fn assert_insert_merge_touching_or_overlapping( - mut before: RangeBoundsMap, bool>, - to_insert: (FiniteBounds, bool), - result: FiniteBounds, - after: [(FiniteBounds, bool); N], + mut before: RangeBoundsMap, bool>, + to_insert: (DiscreteFiniteBounds, bool), + result: DiscreteFiniteBounds, + after: [(DiscreteFiniteBounds, bool); N], ) { assert_eq!( before.insert_merge_touching_or_overlapping(to_insert.0, to_insert.1), @@ -2170,7 +2170,7 @@ mod tests { } } } - fn con(x: Option>, point: &i8) -> bool { + fn con(x: Option>, point: &i8) -> bool { match x { Some(y) => contains_point(y, *point), None => false, @@ -2203,7 +2203,7 @@ mod tests { // Test Helper Functions //====================== - fn all_non_overlapping_test_bound_entries() -> Vec<(FiniteBounds, FiniteBounds)> { + fn all_non_overlapping_test_bound_entries() -> Vec<(DiscreteFiniteBounds, DiscreteFiniteBounds)> { let mut output = Vec::new(); for test_bounds1 in all_valid_test_bounds() { for test_bounds2 in all_valid_test_bounds() { @@ -2216,12 +2216,12 @@ mod tests { return output; } - fn all_valid_test_bounds() -> Vec> { + fn all_valid_test_bounds() -> Vec> { let mut output = Vec::new(); for i in NUMBERS { for j in NUMBERS { if i <= j { - output.push(FiniteBounds { start: *i, end: *j }); + output.push(DiscreteFiniteBounds { start: *i, end: *j }); } } } diff --git a/src/range_bounds_set.rs b/src/range_bounds_set.rs index 6d7bc2f..6e6f477 100644 --- a/src/range_bounds_set.rs +++ b/src/range_bounds_set.rs @@ -5,7 +5,7 @@ use serde::de::{SeqAccess, Visitor}; use serde::ser::SerializeSeq; use serde::{Deserialize, Deserializer, Serialize, Serializer}; -use crate::discrete_bounds::FiniteBounds; +use crate::discrete_finite_bounds::DiscreteFiniteBounds; use crate::discrete_finite::DiscreteFinite; use crate::range_bounds_map::{FiniteRange, IntoIter as RangeBoundsMapIntoIter}; use crate::{OverlapError, RangeBoundsMap}; @@ -62,7 +62,7 @@ where self.inner.overlapping(range).map(first) } /// See [`RangeBoundsMap::get_entry_at_point()`] for more details. - pub fn get_at_point(&self, point: I) -> Result> { + pub fn get_at_point(&self, point: I) -> Result> { self.inner.get_entry_at_point(point).map(first).copied() } /// See [`RangeBoundsMap::contains_point()`] for more details. @@ -81,15 +81,15 @@ where self.inner.remove_overlapping(range).map(first) } /// See [`RangeBoundsMap::cut()`] for more details. - pub fn cut<'a, Q>(&'a mut self, range: Q) -> impl Iterator> + '_ + pub fn cut<'a, Q>(&'a mut self, range: Q) -> impl Iterator> + '_ where Q: FiniteRange + Copy + 'a, - K: From>, + K: From>, { self.inner.cut(range).map(first) } /// See [`RangeBoundsMap::gaps()`] for more details. - pub fn gaps<'a, Q>(&'a self, range: Q) -> impl DoubleEndedIterator> + '_ + pub fn gaps<'a, Q>(&'a self, range: Q) -> impl DoubleEndedIterator> + '_ where Q: FiniteRange + Copy + 'a, { @@ -109,28 +109,28 @@ where /// See [`RangeBoundsMap::insert_merge_touching()`] for more details. pub fn insert_merge_touching(&mut self, range: K) -> Result where - K: From>, + K: From>, { self.inner.insert_merge_touching(range, ()) } /// See [`RangeBoundsMap::insert_merge_overlapping()`] for more details. pub fn insert_merge_overlapping(&mut self, range: K) -> K where - K: From>, + K: From>, { self.inner.insert_merge_overlapping(range, ()) } /// See [`RangeBoundsMap::insert_merge_touching_or_overlapping()`] for more details. pub fn insert_merge_touching_or_overlapping(&mut self, range: K) -> K where - K: From>, + K: From>, { self.inner.insert_merge_touching_or_overlapping(range, ()) } /// See [`RangeBoundsMap::insert_overwrite()`] for more details. pub fn insert_overwrite(&mut self, range: K) where - K: From>, + K: From>, { self.inner.insert_overwrite(range, ()) } diff --git a/src/test_ranges.rs b/src/test_ranges.rs index 7f83f16..ab67e21 100644 --- a/src/test_ranges.rs +++ b/src/test_ranges.rs @@ -1,26 +1,26 @@ -use crate::discrete_bounds::FiniteBounds; +use crate::discrete_finite_bounds::DiscreteFiniteBounds; use crate::discrete_finite::DiscreteFinite; -pub fn uu() -> FiniteBounds { - FiniteBounds { +pub fn uu() -> DiscreteFiniteBounds { + DiscreteFiniteBounds { start: i8::MIN, end: i8::MAX, } } -pub fn ui(x: i8) -> FiniteBounds { - FiniteBounds { +pub fn ui(x: i8) -> DiscreteFiniteBounds { + DiscreteFiniteBounds { start: i8::MIN, end: x, } } -pub fn ue(x: i8) -> FiniteBounds { - FiniteBounds { +pub fn ue(x: i8) -> DiscreteFiniteBounds { + DiscreteFiniteBounds { start: i8::MIN, end: x.down().unwrap(), } } -pub fn iu(x: i8) -> FiniteBounds { - FiniteBounds { +pub fn iu(x: i8) -> DiscreteFiniteBounds { + DiscreteFiniteBounds { start: x, end: i8::MAX, } @@ -28,23 +28,23 @@ pub fn iu(x: i8) -> FiniteBounds { //fn eu(x: i8) -> TestBounds { //(Bound::Excluded(x), Bound::Unbounded) //} -pub fn ii(x1: i8, x2: i8) -> FiniteBounds { - FiniteBounds { start: x1, end: x2 } +pub fn ii(x1: i8, x2: i8) -> DiscreteFiniteBounds { + DiscreteFiniteBounds { start: x1, end: x2 } } -pub fn ie(x1: i8, x2: i8) -> FiniteBounds { - FiniteBounds { +pub fn ie(x1: i8, x2: i8) -> DiscreteFiniteBounds { + DiscreteFiniteBounds { start: x1, end: x2.down().unwrap(), } } -pub fn ei(x1: i8, x2: i8) -> FiniteBounds { - FiniteBounds { +pub fn ei(x1: i8, x2: i8) -> DiscreteFiniteBounds { + DiscreteFiniteBounds { start: x1.up().unwrap(), end: x2, } } -pub fn ee(x1: i8, x2: i8) -> FiniteBounds { - FiniteBounds { +pub fn ee(x1: i8, x2: i8) -> DiscreteFiniteBounds { + DiscreteFiniteBounds { start: x1.up().unwrap(), end: x2.down().unwrap(), } diff --git a/src/utils.rs b/src/utils.rs index eb3a613..7c15ddc 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -19,7 +19,7 @@ along with range_bounds_map. If not, see . use std::cmp::Ordering; -use crate::discrete_bounds::FiniteBounds; +use crate::discrete_finite_bounds::DiscreteFiniteBounds; use crate::discrete_finite::DiscreteFinite; use crate::range_bounds_map::FiniteRange; @@ -71,9 +71,9 @@ where } enum SortedConfig { - NonOverlapping(FiniteBounds, FiniteBounds), - PartialOverlap(FiniteBounds, FiniteBounds), - Swallowed(FiniteBounds, FiniteBounds), + NonOverlapping(DiscreteFiniteBounds, DiscreteFiniteBounds), + PartialOverlap(DiscreteFiniteBounds, DiscreteFiniteBounds), + Swallowed(DiscreteFiniteBounds, DiscreteFiniteBounds), } fn sorted_config(a: A, b: B) -> SortedConfig where @@ -81,11 +81,11 @@ where B: FiniteRange + Copy, I: Ord, { - let ae = FiniteBounds { + let ae = DiscreteFiniteBounds { start: a.start(), end: a.end(), }; - let be = FiniteBounds { + let be = DiscreteFiniteBounds { start: b.start(), end: b.end(), }; @@ -110,9 +110,9 @@ where #[derive(Debug)] pub(crate) struct CutResult { - pub(crate) before_cut: Option>, - pub(crate) inside_cut: Option>, - pub(crate) after_cut: Option>, + pub(crate) before_cut: Option>, + pub(crate) inside_cut: Option>, + pub(crate) after_cut: Option>, } pub(crate) fn cut_range(base: B, cut: C) -> CutResult where @@ -128,54 +128,54 @@ where match config(base, cut) { Config::LeftFirstNonOverlapping => { - result.before_cut = Some(FiniteBounds { + result.before_cut = Some(DiscreteFiniteBounds { start: base.start(), end: base.end(), }); } Config::LeftFirstPartialOverlap => { - result.before_cut = Some(FiniteBounds { + result.before_cut = Some(DiscreteFiniteBounds { start: base.start(), end: cut.start().down().unwrap(), }); - result.inside_cut = Some(FiniteBounds { + result.inside_cut = Some(DiscreteFiniteBounds { start: cut.start(), end: base.end(), }); } Config::LeftContainsRight => { - result.before_cut = Some(FiniteBounds { + result.before_cut = Some(DiscreteFiniteBounds { start: base.start(), end: cut.start().down().unwrap(), }); - result.inside_cut = Some(FiniteBounds { + result.inside_cut = Some(DiscreteFiniteBounds { start: cut.start(), end: cut.end(), }); - result.after_cut = Some(FiniteBounds { + result.after_cut = Some(DiscreteFiniteBounds { start: cut.end().up().unwrap(), end: base.end(), }); } Config::RightFirstNonOverlapping => { - result.after_cut = Some(FiniteBounds { + result.after_cut = Some(DiscreteFiniteBounds { start: base.start(), end: base.end(), }); } Config::RightFirstPartialOverlap => { - result.after_cut = Some(FiniteBounds { + result.after_cut = Some(DiscreteFiniteBounds { start: cut.end().up().unwrap(), end: base.end(), }); - result.inside_cut = Some(FiniteBounds { + result.inside_cut = Some(DiscreteFiniteBounds { start: base.start(), end: cut.end(), }); } Config::RightContainsLeft => { - result.inside_cut = Some(FiniteBounds { + result.inside_cut = Some(DiscreteFiniteBounds { start: base.start(), end: base.end(), });