pub struct RangeList<E: PartialOrd> { /* private fields */ }
Expand description
A sorted collection of inclusive ranges that can be used to represent non-continuous sets of values.
§Warning
Although RangeList
can be constructed for elements that do not implement
std::cmp::Ord
, but do implement std::cmp::PartialOrd
, constructor
methods, such as the FromIterator
implementation, will panic if the used
boundary values cannot be sorted. This requirement allows the usage of types
like f64
, as long as the user can guarantee that values that cannot be
ordered, like NaN
, will not appear.
Implementations§
Source§impl<E: PartialOrd> RangeList<E>
impl<E: PartialOrd> RangeList<E>
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the range list contains no items.
§Examples
assert!(!RangeList::from_iter([3..=4]).is_empty());
assert!(RangeList::<i64>::default().is_empty());
assert!(RangeList::from_iter([3..=2]).is_empty());
Sourcepub fn contains(&self, item: &E) -> bool
pub fn contains(&self, item: &E) -> bool
Returns true
if item
is contained in the range list.
§Examples
assert!(RangeList::from_iter([1..=4]).contains(&4));
assert!(!RangeList::from_iter([1..=4]).contains(&0));
assert!(RangeList::from_iter([1..=4, 6..=7, -5..=-3]).contains(&7));
assert!(!RangeList::from_iter([1..=4, 6..=7, -5..=-3]).contains(&0));
Sourcepub fn lower_bound(&self) -> Option<&E>
pub fn lower_bound(&self) -> Option<&E>
Returns the lower bound of the range list, or None
if the range list is
empty.
§Examples
assert_eq!(RangeList::from_iter([1..=4]).lower_bound(), Some(&1));
assert_eq!(RangeList::from_iter([1..=4, 6..=7, -5..=-3]).lower_bound(), Some(&-5));
assert_eq!(RangeList::<i64>::default().lower_bound(), None);
Sourcepub fn upper_bound(&self) -> Option<&E>
pub fn upper_bound(&self) -> Option<&E>
Returns the upper bound of the range list, or None
if the range list is
empty
§Examples
assert_eq!(RangeList::from_iter([1..=4]).upper_bound(), Some(&4));
assert_eq!(RangeList::from_iter([1..=4, 6..=7, -5..=-3]).upper_bound(), Some(&7));
assert_eq!(RangeList::<i64>::default().upper_bound(), None);
Source§impl<E: PartialOrd + Copy> RangeList<E>
impl<E: PartialOrd + Copy> RangeList<E>
Sourcepub fn iter<'a>(
&'a self,
) -> Map<<&RangeList<E> as IntoIterator>::IntoIter, fn(RangeInclusive<&'a E>) -> RangeInclusive<E>>
pub fn iter<'a>( &'a self, ) -> Map<<&RangeList<E> as IntoIterator>::IntoIter, fn(RangeInclusive<&'a E>) -> RangeInclusive<E>>
Returns an Copying iterator for the ranges in the set.
Trait Implementations§
Source§impl<E: PartialOrd + Clone> From<&RangeInclusive<E>> for RangeList<E>
impl<E: PartialOrd + Clone> From<&RangeInclusive<E>> for RangeList<E>
Source§fn from(value: &RangeInclusive<E>) -> Self
fn from(value: &RangeInclusive<E>) -> Self
Source§impl<E: PartialOrd + Clone> From<RangeInclusive<E>> for RangeList<E>
impl<E: PartialOrd + Clone> From<RangeInclusive<E>> for RangeList<E>
Source§fn from(value: RangeInclusive<E>) -> Self
fn from(value: RangeInclusive<E>) -> Self
Source§impl<E, R> FromIterator<R> for RangeList<E>
impl<E, R> FromIterator<R> for RangeList<E>
Source§fn from_iter<T: IntoIterator<Item = R>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = R>>(iter: T) -> Self
Source§impl<E: PartialOrd + Clone> IntervalIterator<E> for RangeList<E>
impl<E: PartialOrd + Clone> IntervalIterator<E> for RangeList<E>
Source§type IntervalIter = <RangeList<E> as IntoIterator>::IntoIter
type IntervalIter = <RangeList<E> as IntoIterator>::IntoIter
Source§fn intervals(&self) -> Self::IntervalIter
fn intervals(&self) -> Self::IntervalIter
Source§fn diff<O, R>(&self, other: &O) -> R
fn diff<O, R>(&self, other: &O) -> R
other
. Read moreSource§fn disjoint<O: IntervalIterator<E> + ?Sized>(&self, other: &O) -> bool
fn disjoint<O: IntervalIterator<E> + ?Sized>(&self, other: &O) -> bool
self
and other
are disjoint setsSource§fn intersect<O, R>(&self, other: &O) -> R
fn intersect<O, R>(&self, other: &O) -> R
Source§fn subset<O: IntervalIterator<E> + ?Sized>(&self, other: &O) -> bool
fn subset<O: IntervalIterator<E> + ?Sized>(&self, other: &O) -> bool
self
is a subset of other
Source§fn superset<O: IntervalIterator<E> + ?Sized>(&self, other: &O) -> bool
fn superset<O: IntervalIterator<E> + ?Sized>(&self, other: &O) -> bool
self
is a superset of other