From d0f03889d6f2806c09ae2a41e9cdad2d2d224f83 Mon Sep 17 00:00:00 2001 From: ripytide Date: Tue, 6 Dec 2022 21:28:40 +0000 Subject: [PATCH] passing more tests after reworking gaps() --- src/range_bounds_map.rs | 43 +++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/src/range_bounds_map.rs b/src/range_bounds_map.rs index 3fdd483..d39db9d 100644 --- a/src/range_bounds_map.rs +++ b/src/range_bounds_map.rs @@ -775,13 +775,18 @@ where Q: RangeBounds, { // I'm in love with how clean/mindblowing this entire function is - let inners = self + let overlapping = self .overlapping(outer_range_bounds) .map(|(key, _)| (key.start_bound(), key.end_bound())); - // We have to opposite these ahead of time as we actually want - // the bounds included not excluded like with other bounds in - // artificials + // If the start or end point of outer_range_bounds is not + // contained within a RangeBounds in the map then we need to + // generate a artificial RangeBounds to use instead. + // + // We also have to flip the artificial ones ahead of time as + // we actually want the search_range_bounds endpoints included + // not excluded unlike with other bounds in artificials + let artificial_start = ( flip_bound(outer_range_bounds.start_bound()), flip_bound(outer_range_bounds.start_bound()), @@ -790,10 +795,36 @@ where flip_bound(outer_range_bounds.end_bound()), flip_bound(outer_range_bounds.end_bound()), ); - let artificials = once(artificial_start) - .chain(inners) + let mut artificials = once(artificial_start) + .chain(overlapping) .chain(once(artificial_end)); + let start_contained = match outer_range_bounds.start_bound() { + Bound::Included(point) => self.contains_point(point), + Bound::Excluded(point) => self.contains_point(point), + Bound::Unbounded => self.starts.first_key_value().is_some_and( + |(_, (range_bounds, _))| { + range_bounds.start_bound() == Bound::Unbounded + }, + ), + }; + let end_contained = match outer_range_bounds.end_bound() { + Bound::Included(point) => self.contains_point(point), + Bound::Excluded(point) => self.contains_point(point), + Bound::Unbounded => self.starts.last_key_value().is_some_and( + |(_, (range_bounds, _))| { + range_bounds.end_bound() == Bound::Unbounded + }, + ), + }; + + if start_contained { + artificials.next(); + } + if end_contained { + artificials.next_back(); + } + return artificials .tuple_windows() .map(|((_, first_end), (second_start, _))| {