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>
where T: Ord + Clone, RawInterval<T>: Normalize,

source

pub fn new() -> Self

Constructs a new empty Selection.

§Examples
let sel: Selection<i32> = Selection::new();
source

pub fn empty() -> Self

Constructs a new empty Selection.

source

pub fn full() -> Self

Constructs a new full Selection.

§Examples
let sel: Selection<i32> = Selection::full();

 
source

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)));
source

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)));
source

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));
source

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));
source

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);
source

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);
source

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);
source

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);
source

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);
source

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);
source

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);
source

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);
source

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),
]);
source

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)]);
source

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)]);
source

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)]);
source

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));
source

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));
source

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)]);
source

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)]);
source

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)]);
source

pub fn interval_iter(&self) -> IntervalIter<'_, T>

Returns an iterator over each of the Intervals in the Selection.

source

pub fn into_interval_iter(self) -> IntoIntervalIter<T>

Returns an iterator over each of the Intervals in the Selection.

source§

impl<T> Selection<T>
where T: Ord + Clone + Finite,

source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over each of the points in the Selection.

Trait Implementations§

source§

impl<T: Clone> Clone for Selection<T>

source§

fn clone(&self) -> Selection<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Selection<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Default for Selection<T>
where T: Ord + Clone, RawInterval<T>: Normalize,

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T> Extend<Interval<T>> for Selection<T>
where T: Ord + Clone, RawInterval<T>: Normalize,

source§

fn extend<I>(&mut self, iter: I)
where I: IntoIterator<Item = Interval<T>>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<T> From<Interval<T>> for Selection<T>
where T: Ord + Clone, RawInterval<T>: Normalize,

source§

fn from(interval: Interval<T>) -> Self

Converts to this type from the input type.
source§

impl<T> FromIterator<Interval<T>> for Selection<T>
where T: Ord + Clone, RawInterval<T>: Normalize,

source§

fn from_iter<I>(iter: I) -> Self
where I: IntoIterator<Item = Interval<T>>,

Creates a value from an iterator. Read more
source§

impl<T> FromIterator<T> for Selection<T>
where T: Ord + Clone, RawInterval<T>: Normalize,

source§

fn from_iter<I>(iter: I) -> Self
where I: IntoIterator<Item = T>,

Creates a value from an iterator. Read more
source§

impl<T: Hash> Hash for Selection<T>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a, T> IntoIterator for &'a Selection<T>
where T: Ord + Clone + Finite,

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T> IntoIterator for Selection<T>
where T: Ord + Clone + Finite,

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T: PartialEq> PartialEq for Selection<T>

source§

fn eq(&self, other: &Selection<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Eq> Eq for Selection<T>

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.