Struct normalize_interval::selection::Selection
source · pub struct Selection<T>(/* private fields */);Expand description
A possibly noncontiguous collection of Intervals of the type T.
Implementations§
source§impl<T> Selection<T>
impl<T> Selection<T>
sourcepub fn lower_bound(&self) -> Option<Bound<T>>
pub fn lower_bound(&self) -> Option<Bound<T>>
Returns the lower Bound of the Selection, or None if the
Selection is empty.
§Examples
let sel: Selection<i32> = Selection::from(Interval::closed(-3, 5));
assert_eq!(sel.lower_bound(), Some(Include(-3)));Finite types will have their bounds closed:
let sel: Selection<i32> = Selection::from(Interval::open(-3, 5));
assert_eq!(sel.lower_bound(), Some(Include(-2)));sourcepub fn upper_bound(&self) -> Option<Bound<T>>
pub fn upper_bound(&self) -> Option<Bound<T>>
Returns the upper Bound of the Selection, or None if the
Selection is empty.
§Examples
let sel: Selection<i32> = Selection::from(Interval::closed(-3, 5));
assert_eq!(sel.upper_bound(), Some(Include(5)));Finite types will have their bounds closed:
let sel: Selection<i32> = Selection::from(Interval::open(-3, 5));
assert_eq!(sel.upper_bound(), Some(Include(4)));sourcepub fn infimum(&self) -> Option<T>
pub fn infimum(&self) -> Option<T>
Returns the greatest lower bound of the Selection, or None if the
Selection is empty.
§Examples
let sel: Selection<i32> = Selection::from(Interval::open(-3, 5));
assert_eq!(sel.infimum(), Some(-3));Finite types will have their bounds closed:
let sel: Selection<i32> = Selection::from(Interval::open(-3, 5));
assert_eq!(sel.infimum(), Some(-3));sourcepub fn supremum(&self) -> Option<T>
pub fn supremum(&self) -> Option<T>
Returns the least upper bound of the Interval, or None if the
Interval is empty.
§Examples
let sel: Selection<i32> = Selection::from(Interval::open(-3, 5));
assert_eq!(sel.supremum(), Some(5));Finite types will have their bounds closed:
let sel: Selection<i32> = Selection::from(Interval::open(-3, 5));
assert_eq!(sel.supremum(), Some(5));sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the interval contains no points.
§Example
let sel: Selection<i32> = Selection::from(Interval::closed(-3, 5));
assert_eq!(sel.is_empty(), false);
let sel: Selection<i32> = Selection::from(Interval::empty());
assert_eq!(sel.is_empty(), true);sourcepub fn is_full(&self) -> bool
pub fn is_full(&self) -> bool
Returns true if the interval contains all points.
§Example
let sel: Selection<i32> = Selection::from(Interval::closed(-3, 5));
assert_eq!(sel.is_full(), false);
let sel: Selection<i32> = Selection::from(Interval::full());
assert_eq!(sel.is_full(), true);sourcepub fn is_bounded(&self) -> bool
pub fn is_bounded(&self) -> bool
Returns true if the the interval is bounded.
§Example
let sel: Interval<i32> = Interval::open(-2, 4);
assert_eq!(sel.is_left_bounded(), true);
let sel: Interval<i32> = Interval::unbounded_to(-3);
assert_eq!(sel.is_left_bounded(), true);sourcepub fn is_left_bounded(&self) -> bool
pub fn is_left_bounded(&self) -> bool
Returns true if the the Selection is left-bounded.
§Example
let sel: Selection<i32> = Interval::open(-2, 4).into();
assert_eq!(sel.is_left_bounded(), true);
let sel: Selection<i32> = Interval::unbounded_to(-3).into();
assert_eq!(sel.is_left_bounded(), true);sourcepub fn is_right_bounded(&self) -> bool
pub fn is_right_bounded(&self) -> bool
Returns true if the the Selection is right-bounded.
§Example
let sel: Selection<i32> = Interval::open(-2, 4).into();
assert_eq!(sel.is_right_bounded(), true);
let sel: Selection<i32> = Interval::unbounded_from(-3).into();
assert_eq!(sel.is_right_bounded(), true);sourcepub fn is_half_bounded(&self) -> bool
pub fn is_half_bounded(&self) -> bool
Returns true if the the Selection is helf-bounded.
§Example
let sel: Selection<i32> = Interval::unbounded_to(-2).into();
assert_eq!(sel.is_half_bounded(), false);
let sel: Selection<i32> = Interval::full().into();
assert_eq!(sel.is_half_bounded(), false);sourcepub fn contains(&self, point: &T) -> bool
pub fn contains(&self, point: &T) -> bool
Returns true if the the Selection contains the given point.
§Example
let sel: Selection<i32> = Selection::from(Interval::closed(0, 20));
assert_eq!(sel.contains(&2), true);
assert_eq!(sel.contains(&-15), false);sourcepub fn intersects(&self, other: &Self) -> bool
pub fn intersects(&self, other: &Self) -> bool
Returns true if the Selection overlaps the given Selection.
§Example
let a: Selection<i32> = Selection::from(Interval::closed(-3, 5));
let b: Selection<i32> = Selection::from(Interval::closed(4, 15));
assert_eq!(a.intersects(&b), true);
let a: Selection<i32> = Selection::from(Interval::closed(-3, 5));
let b: Selection<i32> = Selection::from(Interval::closed(8, 12));
assert_eq!(a.intersects(&b), false);sourcepub fn complement(&self) -> Self
pub fn complement(&self) -> Self
Returns the Selection containing all points in not contained in the
Selection.
§Example
let sel: Selection<i32> = Selection::from(Interval::open(-3, 5));
assert_eq!(sel.complement().interval_iter().collect::<Vec<_>>(),
vec![
Interval::unbounded_to(-3i32),
Interval::unbounded_from(5i32)
]);Finite types will have their bounds closed:
let sel: Selection<i32> = Selection::from(Interval::closed(-3, 5));
assert_eq!(sel.complement().interval_iter().collect::<Vec<_>>(), vec![
Interval::closed(i32::MIN, -4i32),
Interval::closed(6i32, i32::MAX),
]);sourcepub fn intersect(&self, other: &Self) -> Self
pub fn intersect(&self, other: &Self) -> Self
Returns the Selection containing all points in both the given
Selections.
§Example
let a: Selection<i32> = Selection::from(Interval::closed(-3, 7));
let b: Selection<i32> = Selection::from(Interval::closed(4, 13));
assert_eq!(a.intersect(&b).interval_iter().collect::<Vec<_>>(),
vec![Interval::closed(4, 7)]);Finite types will have their bounds closed:
let a: Selection<i32> = Selection::from(Interval::open(-3, 7));
let b: Selection<i32> = Selection::from(Interval::open(4, 13));
assert_eq!(a.intersect(&b).interval_iter().collect::<Vec<_>>(),
vec![Interval::closed(5, 6)]);sourcepub fn union(&self, other: &Self) -> Self
pub fn union(&self, other: &Self) -> Self
Returns the Selection containing all points in either of the given
Selections.
§Example
let a: Selection<i32> = Selection::from(Interval::closed(-3, 7));
let b: Selection<i32> = Selection::from(Interval::closed(4, 13));
assert_eq!(a.union(&b).interval_iter().collect::<Vec<_>>(),
vec![Interval::closed(-3, 13)]);Finite types will have their bounds closed:
let a: Selection<i32> = Selection::from(Interval::open(-3, 7));
let b: Selection<i32> = Selection::from(Interval::open(4, 13));
assert_eq!(a.union(&b).interval_iter().collect::<Vec<_>>(),
vec![Interval::closed(-2, 12)]);sourcepub fn minus(&self, other: &Self) -> Self
pub fn minus(&self, other: &Self) -> Self
Returns the Selection containing all points in the Selection which
are not in the given Selections.
§Example
let a: Selection<i32> = Selection::from(Interval::closed(-3, 7));
let b: Selection<i32> = Selection::from(Interval::closed(4, 13));
assert_eq!(a.minus(&b).interval_iter().collect::<Vec<_>>(),
vec![Interval::right_open(-3, 4)]);sourcepub fn enclose(&self) -> Interval<T>
pub fn enclose(&self) -> Interval<T>
Returns the smallest Interval containing all of the points in the
Selection.
§Example
let a: Selection<i32> = Selection::from(Interval::open(-3, 5));
let b: Selection<i32> = Selection::from(Interval::closed(9, 13));
let sel = a.union(&b);
assert_eq!(sel.enclose(), Interval::left_open(-3, 13));sourcepub fn closure(&self) -> Interval<T>
pub fn closure(&self) -> Interval<T>
Returns the smallest closed Interval containing all of the points
in the Selection.
§Example
let a: Selection<i32> = Selection::from(Interval::open(-3, 5));
let b: Selection<i32> = Selection::from(Interval::closed(9, 13));
let sel = a.union(&b);
assert_eq!(sel.enclose(), Interval::closed(-2, 13));sourcepub fn intersect_in_place(&mut self, interval: Interval<T>)
pub fn intersect_in_place(&mut self, interval: Interval<T>)
Reduces the Selection to only those points contained in the given
Interval.
§Example
let mut sel: Selection<i32> = Selection::from(Interval::closed(-3, 7));
sel.intersect_in_place(Interval::open(2, 5));
assert_eq!(sel.interval_iter().collect::<Vec<_>>(),
[Interval::open(2, 5)]);Finite types will have their bounds closed:
let mut sel: Selection<i32> = Selection::from(Interval::closed(-3, 7));
sel.intersect_in_place(Interval::open(2, 5));
assert_eq!(sel.interval_iter().collect::<Vec<_>>(),
[Interval::closed(3, 4)]);sourcepub fn union_in_place(&mut self, interval: Interval<T>)
pub fn union_in_place(&mut self, interval: Interval<T>)
Adds all of the points in the given Interval to the Selection.
§Example
let mut sel: Selection<i32> = Selection::from(Interval::closed(-3, 7));
sel.union_in_place(Interval::open(12, 15));
assert_eq!(sel.interval_iter().collect::<Vec<_>>(),
[Interval::closed(-3, 7), Interval::open(12, 15)]);Finite types will have their bounds closed:
let mut sel: Selection<i32> = Selection::from(Interval::open(-3, 8));
sel.union_in_place(Interval::open(7, 10));
assert_eq!(sel.interval_iter().collect::<Vec<_>>(),
[Interval::closed(-2, 9)]);sourcepub fn minus_in_place(&mut self, interval: Interval<T>)
pub fn minus_in_place(&mut self, interval: Interval<T>)
Removes all of the points in the given Interval from the Selection.
§Example
let mut sel: Selection<i32> = Selection::from(Interval::closed(-3, 7));
sel.minus_in_place(Interval::open(2, 5));
assert_eq!(sel.interval_iter().collect::<Vec<_>>(),
[Interval::closed(-3, 2), Interval::closed(5, 7)]);Finite types will have their bounds closed:
let mut sel: Selection<i32> = Selection::from(Interval::closed(-3, 7));
sel.minus_in_place(Interval::closed(2, 5));
assert_eq!(sel.interval_iter().collect::<Vec<_>>(),
[Interval::closed(-3, 1), Interval::closed(6, 7)]);sourcepub fn interval_iter(&self) -> IntervalIter<'_, T> ⓘ
pub fn interval_iter(&self) -> IntervalIter<'_, T> ⓘ
Returns an iterator over each of the Intervals in the Selection.
sourcepub fn into_interval_iter(self) -> IntoIntervalIter<T> ⓘ
pub fn into_interval_iter(self) -> IntoIntervalIter<T> ⓘ
Returns an iterator over each of the Intervals in the Selection.
Trait Implementations§
source§impl<T> Extend<Interval<T>> for Selection<T>
impl<T> Extend<Interval<T>> for Selection<T>
source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = Interval<T>>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = Interval<T>>,
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)source§impl<T> FromIterator<Interval<T>> for Selection<T>
impl<T> FromIterator<Interval<T>> for Selection<T>
source§impl<T> FromIterator<T> for Selection<T>
impl<T> FromIterator<T> for Selection<T>
source§fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
source§impl<'a, T> IntoIterator for &'a Selection<T>
impl<'a, T> IntoIterator for &'a Selection<T>
source§impl<T> IntoIterator for Selection<T>
impl<T> IntoIterator for Selection<T>
impl<T: Eq> Eq for Selection<T>
impl<T> StructuralPartialEq for Selection<T>
Auto Trait Implementations§
impl<T> Freeze for Selection<T>
impl<T> RefUnwindSafe for Selection<T>where
T: RefUnwindSafe,
impl<T> Send for Selection<T>where
T: Send,
impl<T> Sync for Selection<T>where
T: Sync,
impl<T> Unpin for Selection<T>
impl<T> UnwindSafe for Selection<T>where
T: RefUnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)