Skip to main content

common_range_tools/
iter.rs

1use crate::{
2    AnyIncDecCpCmp, CpCmp, DefaultValues, GetBeginEnd, GetBeginEndOption, IncDecCpCmp, MrsP,
3    NumberIncDecCpCmp, RangeRelation, RiFactory, first_range_begin_end, last_range_begin_end,
4    next_range_begin_end, previous_range_begin_end, range_bounds_to_values, range_relation,
5};
6
7use std::marker::PhantomData;
8use std::mem;
9use std::ops::RangeInclusive;
10use std::ops::{Add, RangeBounds, Sub};
11
12/// Core of the consolidation code.
13pub mod consolidate;
14
15/// The core [Iterator]+[DoubleEndedIterator] for finding range intersections.
16pub struct OverlapIter<T, V, C: IncDecCpCmp<T, V>, R: GetBeginEnd<T>, F: GetBeginEndOption<T, R>> {
17    src: Vec<R>,
18    step: V,
19    cmp: C,
20    next: Option<R>,
21    back: Option<R>,
22    last_next: Option<R>,
23    last_back: Option<R>,
24    factory: F,
25    _marker: PhantomData<T>,
26}
27
28impl<T, V, C: IncDecCpCmp<T, V>, R: GetBeginEnd<T>, F: GetBeginEndOption<T, R>>
29    OverlapIter<T, V, C, R, F>
30{
31    /// Creates a new [OverlapIter] from the slice of R.
32    pub fn new(src: Vec<R>, step: V, cmp: C, factory: F) -> Self {
33        let mut res = Self {
34            src,
35            step,
36            cmp,
37            next: None,
38            back: None,
39            last_next: None,
40            last_back: None,
41            factory,
42            _marker: PhantomData,
43        };
44        res.reset();
45        return res;
46    }
47
48    /// Resets this instance to it's starting state.
49    pub fn reset(&mut self) {
50        let src = &self.src;
51        let step = &self.step;
52        let cmp = &self.cmp;
53        let next = self.factory.factory(first_range_begin_end(src, step, cmp));
54        let back = self.factory.factory(last_range_begin_end(src, step, cmp));
55        self.next = next;
56        self.back = back;
57        self.last_back = None;
58        self.last_next = None;
59    }
60
61    /// Tries to copy the src ref range via the internals.
62    /// Returns None if it fails.
63    pub fn copy_range<U: GetBeginEnd<T>>(&self, src: &U) -> Option<R> {
64        let a = self.cmp.cp(src.get_begin());
65        let z = self.cmp.cp(src.get_end());
66        return self.factory.factory(Some((a, z)));
67    }
68
69    /// Returns a tuple of Option refs to the internal next and last_next ranges.
70    pub fn ln(&self) -> (Option<&R>, Option<&R>) {
71        let a;
72        let b;
73        match &self.next {
74            Some(n) => a = Some(n),
75            _ => a = None,
76        }
77        match &self.last_next {
78            Some(n) => b = Some(n),
79            _ => b = None,
80        }
81
82        return (a, b);
83    }
84
85    /// Returns a tuple of Option refs to the internal back and last_back ranges.
86    pub fn lb(&self) -> (Option<&R>, Option<&R>) {
87        let a;
88        let b;
89        match &self.back {
90            Some(n) => a = Some(n),
91            _ => a = None,
92        }
93        match &self.last_back {
94            Some(n) => b = Some(n),
95            _ => b = None,
96        }
97
98        return (a, b);
99    }
100
101    /// After calling [OverlapIter::update_column], call this method in place of [OverlapIter::next] to return the properly updated next value.
102    /// Calling this method resets the curent state of [OverlapIter::next_back].
103    pub fn recompute_next(&mut self) -> Option<R> {
104        self.last_back = None;
105        self.back = self
106            .factory
107            .factory(last_range_begin_end(&self.src, &self.step, &self.cmp));
108
109        let last_next = mem::replace(&mut self.last_next, None);
110        match last_next {
111            Some(x) => self.next = self.try_next(&Some(x)),
112            _ => return None,
113        }
114
115        return self.next();
116    }
117
118    /// After calling [OverlapIter::update_column], call this method in place of [OverlapIter::next_back] to return the properly updated back value.
119    /// Calling this method resets the curent state of [OverlapIter::next].
120    pub fn recompute_back(&mut self) -> Option<R> {
121        self.last_next = None;
122        self.next = self
123            .factory
124            .factory(first_range_begin_end(&self.src, &self.step, &self.cmp));
125        let last_back = mem::replace(&mut self.last_back, None);
126        match last_back {
127            Some(x) => self.back = self.try_next_back(&Some(x)),
128            _ => return None,
129        }
130
131        return self.next_back();
132    }
133
134    /// Updates the internal column to the new [GetBeginEnd] instance.
135    /// Returns [Result::Err] if the range is invalid or if the index point does not exist.
136    ///
137    /// After calling this method the next call to  [OverlapIter::next] or [OverlapIter::next_back] will not function correctly.
138    /// First call the respective [OverlapIter::recompute_next] or [OverlapIter::recompute_back],
139    /// then proceed to call either [OverlapIter::next] or [OverlapIter::next_back] normally.
140    pub fn update_column(&mut self, idx: usize, range: R) -> Result<(), &'static str> {
141        if let Some(col) = self.src.get_mut(idx) {
142            if self.cmp.is_invalid_set(range.get_begin(), range.get_end()) {
143                return Err("Invalid Range");
144            }
145            *col = range;
146            return Ok(());
147        }
148        return Err("No such Column");
149    }
150
151    /// Genrates a new next based on the src passed in.
152    pub fn try_next(&self, src: &Option<R>) -> Option<R> {
153        let mut next = None;
154        if let Some(n) = src {
155            match &self.back {
156                Some(b) => match range_relation(n, b, &self.cmp) {
157                    RangeRelation::Overlap(_) => {
158                        if let Some(begin) = self.cmp.inc(n.get_end(), &self.step) {
159                            next = self.factory.factory(next_range_begin_end(
160                                &begin,
161                                &[
162                                    MrsP {
163                                        r: b,
164                                        _t: PhantomData,
165                                    },
166                                    MrsP {
167                                        r: n,
168                                        _t: PhantomData,
169                                    },
170                                ],
171                                &self.step,
172                                &self.cmp,
173                            ));
174                        }
175                    }
176                    RangeRelation::Before(_) => {
177                        if let Some(begin) = self.cmp.inc(n.get_end(), &self.step) {
178                            next = self.factory.factory(next_range_begin_end(
179                                &begin, &self.src, &self.step, &self.cmp,
180                            ));
181                        }
182                    }
183                    _ => return None,
184                },
185                None => (),
186            }
187        }
188        return next;
189    }
190
191    /// Genrates a new back based on the src passed in.
192    pub fn try_next_back(&self, src: &Option<R>) -> Option<R> {
193        let mut back = None;
194        if let Some(b) = src
195            && let Some(n) = &self.next
196        {
197            match range_relation(b, n, &self.cmp) {
198                RangeRelation::Overlap(_) => {
199                    if let Some(end) = self.cmp.dec(b.get_begin(), &self.step) {
200                        back = self.factory.factory(previous_range_begin_end(
201                            &end,
202                            &[
203                                MrsP {
204                                    r: n,
205                                    _t: PhantomData,
206                                },
207                                MrsP {
208                                    r: b,
209                                    _t: PhantomData,
210                                },
211                            ],
212                            &self.step,
213                            &self.cmp,
214                        ));
215                    }
216                }
217                RangeRelation::After(_) => {
218                    if let Some(end) = self.cmp.dec(b.get_begin(), &self.step) {
219                        back = self.factory.factory(previous_range_begin_end(
220                            &end, &self.src, &self.step, &self.cmp,
221                        ));
222                    }
223                }
224                _ => return None,
225            }
226        }
227        return back;
228    }
229
230    pub fn next_overlaps<'r, 'a>(&mut self) -> Option<(R, OverlapsIter<'r, 'a, T, C, R, R>)> {
231        match self.next() {
232            Some(next) => {
233                if let Some(ln) = &self.last_next {
234                    let i: OverlapsIter<'_, '_, T, C, R, R> =
235                        OverlapsIter::new(&self.cmp, ln, &self.src);
236                    return Some((next, unsafe { mem::transmute(i) }));
237                } else {
238                    return None;
239                }
240            }
241            None => None,
242        }
243    }
244
245    pub fn next_back_overlaps<'r, 'a>(&mut self) -> Option<(R, OverlapsIter<'r, 'a, T, C, R, R>)> {
246        match self.next_back() {
247            Some(next) => {
248                if let Some(lb) = &self.last_back {
249                    let i: OverlapsIter<'_, '_, T, C, R, R> =
250                        OverlapsIter::new(&self.cmp, lb, &self.src);
251                    return Some((next, unsafe { mem::transmute(i) }));
252                } else {
253                    return None;
254                }
255            }
256            None => None,
257        }
258    }
259    /// Converts self to an instance of [OverlapIterWithOverlaps].
260    pub fn into_iter_overlaps<'r, 'a, S: GetBeginEnd<T> + 'r + 'a>(
261        self,
262    ) -> OverlapIterWithOverlaps<'r, 'a, T, V, C, R, S, F> {
263        return OverlapIterWithOverlaps::new(self);
264    }
265}
266
267impl<T, V, C: IncDecCpCmp<T, V>, R: GetBeginEnd<T>, F: GetBeginEndOption<T, R>> Iterator
268    for OverlapIter<T, V, C, R, F>
269{
270    type Item = R;
271
272    /// This is part of a [DoubleEndedIterator] calls to [OverlapIter::next] impact calls to [OverlapIter::next_back].
273    /// ## Big O Notation
274    /// Each call to self.next() is a time complexity of O(n*3)
275    fn next(&mut self) -> Option<Self::Item> {
276        let next = self.try_next(&self.next);
277        if let Some(next) = &self.next {
278            self.last_next = self.copy_range(next);
279        }
280        return mem::replace(&mut self.next, next);
281    }
282}
283
284impl<T, V, C: IncDecCpCmp<T, V>, R: GetBeginEnd<T>, F: GetBeginEndOption<T, R>> DoubleEndedIterator
285    for OverlapIter<T, V, C, R, F>
286{
287    /// This is part of a [DoubleEndedIterator] calls to [OverlapIter::next_back] impact calls to [OverlapIter::next].
288    /// ## Big O Notation
289    /// Each call to self.next_back() is a time complexity of O(n*3)
290    fn next_back(&mut self) -> Option<Self::Item> {
291        let back = self.try_next_back(&self.back);
292        if let Some(back) = &self.back {
293            self.last_back = self.copy_range(back);
294        }
295        return mem::replace(&mut self.back, back);
296    }
297}
298
299/// This acts as a general [OverlapIter] factory.
300///
301/// *The self.add_* methods*:
302///
303/// The various add_* methods return the index of the column that was added and the generated instance of [GetBeginEnd].
304/// The index can be used to update that column during the iteration process
305/// of the returned [OverlapIter] object instance.
306/// See [OverlapIter::update_column] for more details.
307pub struct Intersector<T, V, C: IncDecCpCmp<T, V>, R, F> {
308    list: Vec<R>,
309    step: V,
310    rebound: V,
311    cmp: C,
312    factory: F,
313    _r: PhantomData<(T, R)>,
314}
315
316impl<T, V, C: IncDecCpCmp<T, V>, R: GetBeginEnd<T>, B: GetBeginEndOption<T, R>>
317    Intersector<T, V, C, R, B>
318{
319    /// Constructs a new instance of [Intersector].
320    pub fn new(list: Vec<R>, step: V, rebound: V, cmp: C, factory: B) -> Self {
321        Self {
322            list,
323            step,
324            rebound,
325            cmp,
326            factory,
327            _r: PhantomData,
328        }
329    }
330
331    /// Converts self to an instance of [OverlapIterWithOverlaps].
332    pub fn into_iter_overlaps<'r, 'a, S: GetBeginEnd<T> + 'r + 'a>(
333        self,
334    ) -> OverlapIterWithOverlaps<'r, 'a, T, V, C, R, S, B> {
335        return OverlapIterWithOverlaps::new(self.into_iter());
336    }
337}
338
339impl<T, V> Intersector<T, V, AnyIncDecCpCmp<T>, RangeInclusive<T>, RiFactory<T>>
340where
341    T: PartialOrd + Copy + Add<V, Output = T> + Sub<V, Output = T>,
342    V: Copy,
343{
344    /// Creates a new [Intersector] instance that works with any data type.
345    pub fn any(
346        step: V,
347        rebound: V,
348        min: T,
349        max: T,
350    ) -> Intersector<T, V, AnyIncDecCpCmp<T>, RangeInclusive<T>, RiFactory<T>> {
351        Self {
352            list: Vec::new(),
353            step,
354            rebound,
355            cmp: AnyIncDecCpCmp::new(min, max),
356            factory: RiFactory::new(),
357            _r: PhantomData,
358        }
359    }
360
361    /// Creates a new [DoubleEndedIterator] of [OverlapIter].
362    pub fn any_from(
363        step: V,
364        rebound: V,
365        min: T,
366        max: T,
367        src: &[impl RangeBounds<T>],
368    ) -> OverlapIter<T, V, AnyIncDecCpCmp<T>, RangeInclusive<T>, RiFactory<T>> {
369        let mut i = Self::any(step, rebound, min, max);
370        for r in src {
371            i.add_range(r);
372        }
373        return i.into_iter();
374    }
375
376    /// Creates a new [DoubleEndedIterator] of [OverlapsIter].
377    pub fn any_from_ol<'r, 'a>(
378        step: V,
379        rebound: V,
380        min: T,
381        max: T,
382        src: &[impl RangeBounds<T>],
383    ) -> OverlapIterWithOverlaps<
384        'r,
385        'a,
386        T,
387        V,
388        AnyIncDecCpCmp<T>,
389        RangeInclusive<T>,
390        RangeInclusive<T>,
391        RiFactory<T>,
392    > {
393        let mut i = Self::any(step, rebound, min, max);
394        for r in src {
395            i.add_range(r);
396        }
397        return i.into_iter_overlaps();
398    }
399}
400
401impl<T> Intersector<T, T, NumberIncDecCpCmp<T>, RangeInclusive<T>, RiFactory<T>>
402where
403    T: PartialOrd + Copy + Add<T, Output = T> + Sub<T, Output = T>,
404    NumberIncDecCpCmp<T>: DefaultValues<T, T>,
405{
406    /// Returns a new instance of [Intersector] configured to work with any primitive number type using the default values.
407    pub fn num_defaults() -> Self {
408        let cmp = NumberIncDecCpCmp::defaults();
409        return Self {
410            list: Vec::new(),
411            step: cmp.default_step(),
412            rebound: cmp.default_rebound(),
413            cmp,
414            factory: RiFactory::new(),
415            _r: PhantomData,
416        };
417    }
418
419    /// Returns a new instance of [Intersector] configured to work with numbers based on the arguments passed in.
420    pub fn num(step: T, rebound: T, min: T, max: T) -> Self {
421        return Self {
422            list: Vec::new(),
423            step,
424            rebound,
425            cmp: NumberIncDecCpCmp::new(min, max),
426            factory: RiFactory::new(),
427            _r: PhantomData,
428        };
429    }
430
431    /// Returns a new instance of [Intersector] configured to work with numbers.
432    /// The nteral step and rebound values are set to sr.
433    pub fn num_sr(sr: T) -> Self {
434        return Self {
435            list: Vec::new(),
436            step: sr,
437            rebound: sr,
438            cmp: NumberIncDecCpCmp::defaults(),
439            factory: RiFactory::new(),
440            _r: PhantomData,
441        };
442    }
443
444    /// Takes any list of range of numbers and converts them to an instance of [OverlapIter].
445    pub fn num_from(
446        src: &[impl RangeBounds<T>],
447    ) -> OverlapIter<T, T, NumberIncDecCpCmp<T>, RangeInclusive<T>, RiFactory<T>> {
448        let mut i = Self::num_defaults();
449        for r in src {
450            i.add_range(r);
451        }
452        return i.into_iter();
453    }
454
455    /// Creates a new [DoubleEndedIterator] of [OverlapIter].
456    pub fn num_from_ol<'r, 'a>(
457        src: &[impl RangeBounds<T>],
458    ) -> OverlapIterWithOverlaps<
459        'r,
460        'a,
461        T,
462        T,
463        NumberIncDecCpCmp<T>,
464        RangeInclusive<T>,
465        RangeInclusive<T>,
466        RiFactory<T>,
467    > {
468        let mut i = Self::num_defaults();
469        for r in src {
470            i.add_range(r);
471        }
472        return i.into_iter_overlaps();
473    }
474
475    /// Takes any list of range of numbers and converts them to an instance of [OverlapIter], with the step and rebound value set to sr.
476    pub fn num_sr_from(
477        sr: T,
478        src: &[impl RangeBounds<T>],
479    ) -> OverlapIter<T, T, NumberIncDecCpCmp<T>, RangeInclusive<T>, RiFactory<T>> {
480        let mut i = Self::num_sr(sr);
481        for r in src {
482            i.add_range(r);
483        }
484        return i.into_iter();
485    }
486    /// Creates a new [DoubleEndedIterator] of [OverlapsIter].
487    pub fn num_from_sr_ol<'r, 'a>(
488        sr: T,
489        src: &[impl RangeBounds<T>],
490    ) -> OverlapIterWithOverlaps<
491        'r,
492        'a,
493        T,
494        T,
495        NumberIncDecCpCmp<T>,
496        RangeInclusive<T>,
497        RangeInclusive<T>,
498        RiFactory<T>,
499    > {
500        let mut i = Self::num_sr(sr);
501        for r in src {
502            i.add_range(r);
503        }
504        return i.into_iter_overlaps();
505    }
506}
507
508macro_rules! impl_intersector_num_core{
509    ($($t:ty),*) => {
510        $(
511            impl Intersector<$t, $t, NumberIncDecCpCmp<$t>, RangeInclusive<$t>,RiFactory<$t>>
512            where NumberIncDecCpCmp<$t>: DefaultValues<$t,$t> {}
513
514        )*
515    };
516}
517impl_intersector_num_core!(
518    i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize, f32, f64
519);
520
521impl<T, V, C: IncDecCpCmp<T, V>, R: GetBeginEnd<T>, F: GetBeginEndOption<T, R>>
522    Intersector<T, V, C, R, F>
523{
524    /// Tries to add an instance of [GetBeginEnd] to this instance returns None if src is invalid.
525    pub fn add_raw_range(&mut self, src: R) -> Option<(usize, &R)> {
526        if self.cmp.is_invalid_set(&src.get_begin(), &src.get_end()) {
527            return None;
528        }
529        self.list.push(src);
530        let id = self.list.len() - 1;
531        return Some((id, &self.list[id]));
532    }
533
534    /// Tries to create and add a valid internal range from the tuple of refs.
535    pub fn add_from_tuple_ref(&mut self, src: (&T, &T)) -> Option<(usize, &R)> {
536        let a = self.cmp.cp(src.0);
537        let z = self.cmp.cp(src.1);
538        return self.add_from_tuple((a, z));
539    }
540    /// Tries to add a tuple to the instance, returns None if it fails.
541    pub fn add_from_tuple(&mut self, src: (T, T)) -> Option<(usize, &R)> {
542        match self.factory.factory(Some(src)) {
543            Some(mrs) => return self.add_raw_range(mrs),
544            None => None,
545        }
546    }
547
548    /// This is really a wrapper for [crate::range_bounds_to_values].
549    pub fn rebound(&self, r: &impl RangeBounds<T>) -> Option<(T, T)> {
550        return range_bounds_to_values(r, self.get_rebound(), self.get_cmp());
551    }
552
553    /// Tries to convert a given [RangeBounds] instance to the internal range type.
554    /// Returns None if the conversion process fails or the range produced is invalid.
555    pub fn add_range(&mut self, r: &impl RangeBounds<T>) -> Option<(usize, &R)> {
556        match self.rebound(r) {
557            Some(src) => self.add_tuple(src),
558            None => None,
559        }
560    }
561
562    /// Tries to convert a tuple to the internal range type and add it.
563    /// Returns None if the conversion process fails or the resulting range is invalid.
564    pub fn add_tuple(&mut self, src: (T, T)) -> Option<(usize, &R)> {
565        return self.add_from_tuple(src);
566    }
567
568    /// Returns a mutable ref to the internal instance of [IncDecCpCmp].
569    pub fn get_cmp_mut(&mut self) -> &mut C {
570        return &mut self.cmp;
571    }
572
573    /// Returns a ref to the internal instance of [IncDecCpCmp].
574    pub fn get_cmp(&self) -> &C {
575        return &self.cmp;
576    }
577
578    /// Returns a ref to the internal rebound value.
579    pub fn get_rebound(&self) -> &V {
580        return &self.rebound;
581    }
582
583    /// Returns a ref to the internal step value.
584    pub fn get_step(&self) -> &V {
585        return &self.step;
586    }
587
588    /// Updates the internal rebound value.
589    pub fn set_rebound(&mut self, rebound: V) {
590        self.rebound = rebound;
591    }
592
593    /// Updates the internal step value.
594    pub fn set_step(&mut self, step: V) {
595        self.step = step;
596    }
597}
598
599impl<T, V, C: IncDecCpCmp<T, V>, R: GetBeginEnd<T>, F: GetBeginEndOption<T, R>> IntoIterator
600    for Intersector<T, V, C, R, F>
601{
602    type Item = R;
603
604    type IntoIter = OverlapIter<T, V, C, R, F>;
605
606    /// Converts the current instance of [Intersector] into an instance of [OverlapIter].
607    fn into_iter(self) -> Self::IntoIter {
608        return OverlapIter::new(self.list, self.step, self.cmp, self.factory);
609    }
610}
611
612pub struct OverlapsIter<'r, 'a, T, C: CpCmp<T> + 'r, R: GetBeginEnd<T> + 'r, S: GetBeginEnd<T> + 'a>
613{
614    cmp: &'r C,
615    pos: usize,
616    range: &'r R,
617    list: &'r Vec<S>,
618    _t: PhantomData<(T, &'a S)>,
619}
620
621impl<'r, 'a, C: CpCmp<T>, T, R: GetBeginEnd<T>, S: GetBeginEnd<T> + 'a>
622    OverlapsIter<'r, 'a, T, C, R, S>
623{
624    pub fn new(cmp: &'r C, range: &'r R, list: &'r Vec<S>) -> Self {
625        return Self {
626            cmp,
627            pos: 0,
628            range,
629            list,
630            _t: PhantomData,
631        };
632    }
633
634    pub fn get_range(&self) -> &'r R {
635        return self.range;
636    }
637}
638
639impl<'r, 'a, C: CpCmp<T>, T, R: GetBeginEnd<T>, S: GetBeginEnd<T> + 'a> Iterator
640    for OverlapsIter<'r, 'a, T, C, R, S>
641{
642    type Item = &'a S;
643    fn next(&mut self) -> Option<Self::Item> {
644        let range = self.pos..self.list.len();
645        if range.is_empty() {
646            return None;
647        }
648        let (a, b) = self.range.to_tuple_ref();
649        for pos in range {
650            let cmp = &self.list[pos];
651            self.pos = pos + 1;
652            let (c, d) = cmp.to_tuple_ref();
653            if self.cmp.overlap(a, b, c, d) {
654                return Some(unsafe { mem::transmute(cmp) });
655            }
656        }
657
658        return None;
659    }
660}
661
662pub struct OverlapIterWithOverlaps<
663    'r,
664    'a,
665    T,
666    V,
667    C: IncDecCpCmp<T, V> + 'r,
668    R: GetBeginEnd<T> + 'r,
669    S: GetBeginEnd<T> + 'a,
670    F: GetBeginEndOption<T, R>,
671> {
672    iter: OverlapIter<T, V, C, R, F>,
673    _marker: PhantomData<(&'r C, &'r R, &'a S)>,
674}
675
676impl<
677    'r,
678    'a,
679    T,
680    V,
681    C: IncDecCpCmp<T, V> + 'r,
682    R: GetBeginEnd<T> + 'r,
683    S: GetBeginEnd<T> + 'a,
684    F: GetBeginEndOption<T, R>,
685> OverlapIterWithOverlaps<'r, 'a, T, V, C, R, S, F>
686{
687    pub fn new(iter: OverlapIter<T, V, C, R, F>) -> Self {
688        return Self {
689            iter,
690            _marker: PhantomData,
691        };
692    }
693    pub fn reset(&mut self) {
694        self.iter.reset();
695    }
696}
697
698impl<'r, 'a, T, V, C: IncDecCpCmp<T, V>> Iterator
699    for OverlapIterWithOverlaps<'r, 'a, T, V, C, RangeInclusive<T>, RangeInclusive<T>, RiFactory<T>>
700{
701    type Item = (
702        RangeInclusive<T>,
703        OverlapsIter<'r, 'a, T, C, RangeInclusive<T>, RangeInclusive<T>>,
704    );
705    fn next(&mut self) -> Option<Self::Item> {
706        return self.iter.next_overlaps();
707    }
708}
709
710impl<'r, 'a, T, V, C: IncDecCpCmp<T, V>> DoubleEndedIterator
711    for OverlapIterWithOverlaps<'r, 'a, T, V, C, RangeInclusive<T>, RangeInclusive<T>, RiFactory<T>>
712{
713    fn next_back(&mut self) -> Option<Self::Item> {
714        return self.iter.next_back_overlaps();
715    }
716}