pub struct IntervalSet<Bound: Width> { /* private fields */ }Implementations§
Source§impl<Bound: Width> IntervalSet<Bound>
impl<Bound: Width> IntervalSet<Bound>
Source§impl<Bound> IntervalSet<Bound>
impl<Bound> IntervalSet<Bound>
Sourcepub fn interval_count(&self) -> usize
pub fn interval_count(&self) -> usize
Counts the number of intervals contained in the set.
let single_interval_set = IntervalSet::new(0, 1);
assert_eq!(single_interval_set.interval_count(), 1);
let double_interval_set = [(3,5), (7,7)].to_interval_set();
assert_eq!(double_interval_set.interval_count(), 2);
let empty_interval_set = IntervalSet::<usize>::empty();
assert_eq!(empty_interval_set.interval_count(), 0);Trait Implementations§
Source§impl<'a, 'b, Bound: Num + Width + Clone> Add<&'b Bound> for &'a IntervalSet<Bound>
impl<'a, 'b, Bound: Num + Width + Clone> Add<&'b Bound> for &'a IntervalSet<Bound>
Source§fn add(self, other: &Bound) -> IntervalSet<Bound>
fn add(self, other: &Bound) -> IntervalSet<Bound>
Adds a constant to an interval set.
assert_eq!([(3, 3), (7, 8)].to_interval_set() + 2, [(5, 5), (9, 10)].to_interval_set());This method preserves empty interval sets.
assert!((IntervalSet::empty() + 4).is_empty());It is not possible to add an interval set to a constant.
let _ = 4 + IntervalSet::new(5, 9); // doesn't compileSource§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
+ operator.Source§impl<'b, Bound: Num + Width + Clone> Add<&'b Bound> for IntervalSet<Bound>
impl<'b, Bound: Num + Width + Clone> Add<&'b Bound> for IntervalSet<Bound>
Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
+ operator.Source§impl<'a, 'b, Bound: Num + Width> Add<&'b IntervalSet<Bound>> for &'a IntervalSet<Bound>
impl<'a, 'b, Bound: Num + Width> Add<&'b IntervalSet<Bound>> for &'a IntervalSet<Bound>
Source§fn add(self, other: &IntervalSet<Bound>) -> IntervalSet<Bound>
fn add(self, other: &IntervalSet<Bound>) -> IntervalSet<Bound>
Calculates all values that could result in the addition of two items from each interval set.
let a = [(1, 2), (5, 6)].to_interval_set();
let b = [(1, 1), (4, 5)].to_interval_set();
assert_eq!(a + b, [(2, 3), (5, 7), (9, 11)].to_interval_set());This method preserves empty interval sets.
let a = [(1, 1), (4, 5)].to_interval_set();
let b = IntervalSet::empty();
assert!((a + b).is_empty());Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
+ operator.Source§impl<'b, Bound: Num + Width> Add<&'b IntervalSet<Bound>> for IntervalSet<Bound>
impl<'b, Bound: Num + Width> Add<&'b IntervalSet<Bound>> for IntervalSet<Bound>
Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
+ operator.Source§fn add(self, other: &IntervalSet<Bound>) -> IntervalSet<Bound>
fn add(self, other: &IntervalSet<Bound>) -> IntervalSet<Bound>
+ operation. Read moreSource§impl<'a, Bound: Num + Width + Clone> Add<Bound> for &'a IntervalSet<Bound>
impl<'a, Bound: Num + Width + Clone> Add<Bound> for &'a IntervalSet<Bound>
Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
+ operator.Source§fn add(self, other: Bound) -> IntervalSet<Bound>
fn add(self, other: Bound) -> IntervalSet<Bound>
+ operation. Read moreSource§impl<Bound: Num + Width + Clone> Add<Bound> for IntervalSet<Bound>
impl<Bound: Num + Width + Clone> Add<Bound> for IntervalSet<Bound>
Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
+ operator.Source§fn add(self, other: Bound) -> IntervalSet<Bound>
fn add(self, other: Bound) -> IntervalSet<Bound>
+ operation. Read moreSource§impl<'a, Bound: Num + Width> Add<IntervalSet<Bound>> for &'a IntervalSet<Bound>
impl<'a, Bound: Num + Width> Add<IntervalSet<Bound>> for &'a IntervalSet<Bound>
Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
+ operator.Source§fn add(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>
fn add(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>
+ operation. Read moreSource§impl<Bound: Num + Width> Add for IntervalSet<Bound>
impl<Bound: Num + Width> Add for IntervalSet<Bound>
Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
+ operator.Source§fn add(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>
fn add(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>
+ operation. Read moreSource§impl<Bound> Bot for IntervalSet<Bound>
impl<Bound> Bot for IntervalSet<Bound>
fn bot() -> IntervalSet<Bound>
Source§impl<Bound> Bounded for IntervalSet<Bound>
impl<Bound> Bounded for IntervalSet<Bound>
Source§fn lower(&self) -> Bound
fn lower(&self) -> Bound
Returns the smallest value contained in an interval set.
assert_eq!([(8, 20)].to_interval_set().lower(), 8);
assert_eq!([(-5, 11), (10, 30)].to_interval_set().lower(), -5);
assert_eq!(IntervalSet::singleton(7).lower(), 7);However, this will panic on an empty interval.
IntervalSet::<u8>::empty().lower(); // panics!Source§fn upper(&self) -> Bound
fn upper(&self) -> Bound
Returns the largest value contained in an interval set.
assert_eq!([(8, 20)].to_interval_set().upper(), 20);
assert_eq!([(-5, 11), (10, 30)].to_interval_set().upper(), 30);
assert_eq!(IntervalSet::singleton(7).upper(), 7);However, this will panic on an empty interval.
IntervalSet::<u8>::empty().upper(); // panics!Source§impl<Bound: Width + Num> Cardinality for IntervalSet<Bound>
IsSingleton and IsEmpty are defined automatically in gcollections.
impl<Bound: Width + Num> Cardinality for IntervalSet<Bound>
IsSingleton and IsEmpty are defined automatically in gcollections.
Source§fn size(&self) -> <Bound as Width>::Output
fn size(&self) -> <Bound as Width>::Output
Calculates the size of an interval set (the number of integers it contains). This includes the endpoints of all intervals. The size of the interval set is unsigned, but has the same number of bits as the interval bounds.
assert_eq!(IntervalSet::<i32>::singleton(8).size(), 1 as u32);
assert_eq!(IntervalSet::<usize>::new(1, 10).size(), 10 as usize);
// Default is to use i32.
assert_eq!([(3, 5), (8, 9)].to_interval_set().size(), (3 + 2) as u32);
assert_eq!(IntervalSet::<i64>::empty().size(), 0);
// Doesn't overflow:
assert_eq!(IntervalSet::<usize>::whole().size(), usize::max_value());type Size = <Bound as Width>::Output
Source§impl<Bound: Clone + Width> Clone for IntervalSet<Bound>
impl<Bound: Clone + Width> Clone for IntervalSet<Bound>
Source§fn clone(&self) -> IntervalSet<Bound>
fn clone(&self) -> IntervalSet<Bound>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<Bound: Width> Collection for IntervalSet<Bound>
impl<Bound: Width> Collection for IntervalSet<Bound>
Source§impl<Bound: Width + Num> Complement for IntervalSet<Bound>
impl<Bound: Width + Num> Complement for IntervalSet<Bound>
Source§fn complement(&self) -> IntervalSet<Bound>
fn complement(&self) -> IntervalSet<Bound>
Calculates all values that are excluded from the interval set.
Positive and negative infinity are represented with Interval::whole().lower() and Interval::whole().upper();
assert_eq!(IntervalSet::<i64>::empty().complement(), IntervalSet::whole());
let neg_inf = IntervalSet::<i32>::whole().lower();
let pos_inf = IntervalSet::<i32>::whole().upper();
assert_eq!(IntervalSet::singleton(5).complement(), [(neg_inf, 4), (6, pos_inf)].to_interval_set());
assert_eq!([(2, 5), (8, 10)].to_interval_set().complement(), [(neg_inf, 1), (6, 7), (11, pos_inf)].to_interval_set());Source§impl<Bound: Width + Num> Contains for IntervalSet<Bound>
impl<Bound: Width + Num> Contains for IntervalSet<Bound>
Source§fn contains(&self, value: &Bound) -> bool
fn contains(&self, value: &Bound) -> bool
Calculates whether an interval contains a value.
let interval_set = [(3, 5), (8, 9)].to_interval_set();
assert!(interval_set.contains(&3));
assert!(interval_set.contains(&4));
assert!(interval_set.contains(&5));
assert!(interval_set.contains(&8));
assert!(interval_set.contains(&9));
assert!(!interval_set.contains(&1));
assert!(!interval_set.contains(&2));
assert!(!interval_set.contains(&6));
assert!(!interval_set.contains(&7));
assert!(!interval_set.contains(&10));Source§impl<'de, Bound> Deserialize<'de> for IntervalSet<Bound>
impl<'de, Bound> Deserialize<'de> for IntervalSet<Bound>
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<Bound> Difference<Bound> for IntervalSet<Bound>
impl<Bound> Difference<Bound> for IntervalSet<Bound>
Source§fn difference(&self, rhs: &Bound) -> IntervalSet<Bound>
fn difference(&self, rhs: &Bound) -> IntervalSet<Bound>
Calculates the interval set after removing a single value. This returns the original interval set if the value is not in the interval set.
let interval_set = [(1, 3), (5, 9)].to_interval_set();
assert_eq!(interval_set.difference(&4), interval_set);
assert_eq!(interval_set.difference(&5), [(1, 3), (6, 9)].to_interval_set());
assert_eq!(interval_set.difference(&7), [(1, 3), (5, 6), (8, 9)].to_interval_set());type Output = IntervalSet<Bound>
Source§impl<Bound: Width + Num> Difference for IntervalSet<Bound>
impl<Bound: Width + Num> Difference for IntervalSet<Bound>
Source§fn difference(&self, rhs: &IntervalSet<Bound>) -> IntervalSet<Bound>
fn difference(&self, rhs: &IntervalSet<Bound>) -> IntervalSet<Bound>
Calculates the interval set containing all items in the left set, but not in the right set. The difference is not symmetric.
let a = [(1, 3), (8, 8), (10, 11)].to_interval_set();
let b = [(2, 5), (7, 8), (12, 15)].to_interval_set();
assert_eq!(a.difference(&b), [(1, 1), (10, 11)].to_interval_set());
assert_eq!(b.difference(&a), [(4, 5), (7, 7), (12, 15)].to_interval_set());type Output = IntervalSet<Bound>
Source§impl<Bound: Width + Num> Disjoint for IntervalSet<Bound>
impl<Bound: Width + Num> Disjoint for IntervalSet<Bound>
Source§fn is_disjoint(&self, rhs: &IntervalSet<Bound>) -> bool
fn is_disjoint(&self, rhs: &IntervalSet<Bound>) -> bool
Calculates whether two interval do not contain any shared values.
let a = [(1, 3), (7, 8)].to_interval_set();
let b = [(4, 6)].to_interval_set();
assert!(a.is_disjoint(&b));
assert!(b.is_disjoint(&a));
let a = [(1, 3)].to_interval_set();
let b = [(3, 4), (8, 10)].to_interval_set();
assert!(!a.is_disjoint(&b));
assert!(!b.is_disjoint(&a));Source§impl<Bound: Display + Width + Num> Display for IntervalSet<Bound>
impl<Bound: Display + Width + Num> Display for IntervalSet<Bound>
Source§fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error>
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error>
Formats an interval set.
Empty interval sets are displayed as the empty set “{}”.
Single intervals are displayed as the isolated interval.
Combined intervals are displayed as a sorted set of intervals.
See Interval::fmt for more detail on how intervals are formatted.
assert_eq!(format!("{}", [(3, 5)].to_interval_set()), "[3..5]");
assert_eq!(format!("{}", [(4, 4), (8, 9)].to_interval_set()), "{[4..4][8..9]}");
assert_eq!(format!("{}", IntervalSet::<u32>::empty()), "{}");Source§impl<Bound: Width + Num> Empty for IntervalSet<Bound>
impl<Bound: Width + Num> Empty for IntervalSet<Bound>
Source§fn empty() -> IntervalSet<Bound>
fn empty() -> IntervalSet<Bound>
Constructs an empty interval set.
The type needs to be specified or inferred as Interval is parametrized by its input.
assert_eq!(IntervalSet::<i32>::empty().size(), 0);
assert_eq!(IntervalSet::<u32>::empty().size(), 0);
assert!(IntervalSet::<u16>::empty().is_empty());Source§impl<Bound> Entailment for IntervalSet<Bound>
impl<Bound> Entailment for IntervalSet<Bound>
fn entail(&self, other: &IntervalSet<Bound>) -> SKleene
Source§impl<Bound> Extend<Interval<Bound>> for IntervalSet<Bound>
impl<Bound> Extend<Interval<Bound>> for IntervalSet<Bound>
Source§fn extend<I>(&mut self, iterable: I)where
I: IntoIterator<Item = Interval<Bound>>,
fn extend<I>(&mut self, iterable: I)where
I: IntoIterator<Item = Interval<Bound>>,
Inserts additional intervals into an interval set.
let mut interval_set = IntervalSet::<u32>::empty();
assert_eq!(interval_set, Vec::new().to_interval_set());
interval_set.extend([Interval::new(2, 3), Interval::new(6, 7)]);
// Now the set contains two disjoint intervals.
assert_eq!(interval_set, [(2, 3), (6, 7)].to_interval_set());
// Unify the intervals with the missing items to create a single interval.
interval_set.extend([Interval::singleton(4), Interval::singleton(5)]);
assert_eq!(interval_set, [(2, 7)].to_interval_set());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<Bound> Intersection<Bound> for IntervalSet<Bound>
impl<Bound> Intersection<Bound> for IntervalSet<Bound>
Source§fn intersection(&self, rhs: &Bound) -> IntervalSet<Bound>
fn intersection(&self, rhs: &Bound) -> IntervalSet<Bound>
Calculates whether a value is contained in an interval. Returns the value as an interval set if it is in the interval and an empty interval set if not.
let interval_set = [(1, 4), (6, 7)].to_interval_set();
assert_eq!(interval_set.intersection(&10), IntervalSet::empty());
assert_eq!(interval_set.intersection(&3), IntervalSet::singleton(3));
assert_eq!(interval_set.intersection(&6), IntervalSet::singleton(6));type Output = IntervalSet<Bound>
Source§impl<Bound: Width + Num> Intersection for IntervalSet<Bound>
impl<Bound: Width + Num> Intersection for IntervalSet<Bound>
Source§fn intersection(&self, rhs: &IntervalSet<Bound>) -> IntervalSet<Bound>
fn intersection(&self, rhs: &IntervalSet<Bound>) -> IntervalSet<Bound>
Calculates the intersection of two interval sets. This returns an interval set containing all the values in the both.
let a = [(1, 3), (8, 8), (10, 11)].to_interval_set();
let b = [(2, 5), (7, 8), (12, 15)].to_interval_set();
assert_eq!(a.intersection(&b), [(2, 3), (8, 8)].to_interval_set());type Output = IntervalSet<Bound>
Source§impl<'a, Bound: Width> IntoIterator for &'a IntervalSet<Bound>
impl<'a, Bound: Width> IntoIterator for &'a IntervalSet<Bound>
Source§impl<'a, Bound: Width> IntoIterator for &'a mut IntervalSet<Bound>
impl<'a, Bound: Width> IntoIterator for &'a mut IntervalSet<Bound>
Source§impl<Bound: Width> IntoIterator for IntervalSet<Bound>
impl<Bound: Width> IntoIterator for IntervalSet<Bound>
Source§impl<Bound> Join for IntervalSet<Bound>
impl<Bound> Join for IntervalSet<Bound>
fn join(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>
Source§impl<Bound> Meet for IntervalSet<Bound>
impl<Bound> Meet for IntervalSet<Bound>
fn meet(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>
Source§impl<'a, 'b, Bound: Num + Width + Clone> Mul<&'b Bound> for &'a IntervalSet<Bound>
impl<'a, 'b, Bound: Num + Width + Clone> Mul<&'b Bound> for &'a IntervalSet<Bound>
Source§fn mul(self, other: &Bound) -> IntervalSet<Bound>
fn mul(self, other: &Bound) -> IntervalSet<Bound>
Multiplies an interval set by a constant.
Caution: the resulting interval set is an over-approxmation for the same reason as Interval::mul.
assert_eq!([(1, 2), (5, 6)].to_interval_set() * 2, [(2, 4), (10, 12)].to_interval_set());This method preserves empty interval sets.
assert!((IntervalSet::empty() * 11).is_empty());It is not possible to multiply a constant by an interval set.
let _ = 4 * IntervalSet::new(5, 9); // doesn't compileSource§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
* operator.Source§impl<'b, Bound: Num + Width + Clone> Mul<&'b Bound> for IntervalSet<Bound>
impl<'b, Bound: Num + Width + Clone> Mul<&'b Bound> for IntervalSet<Bound>
Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
* operator.Source§impl<'a, 'b, Bound: Num + Width> Mul<&'b IntervalSet<Bound>> for &'a IntervalSet<Bound>
impl<'a, 'b, Bound: Num + Width> Mul<&'b IntervalSet<Bound>> for &'a IntervalSet<Bound>
Source§fn mul(self, other: &IntervalSet<Bound>) -> IntervalSet<Bound>
fn mul(self, other: &IntervalSet<Bound>) -> IntervalSet<Bound>
Calculates all values that could result in the multiplication of two items from each interval set.
Caution: the resulting interval set is an over-approxmation for the same reason as Interval::mul.
let a = [(1, 2), (5, 6)].to_interval_set();
let b = [(0, 0), (3, 4)].to_interval_set();
assert_eq!(a * b, [(0, 0), (3, 8), (15, 24)].to_interval_set());This method preserves empty interval sets.
assert!((IntervalSet::empty() * [(0, 0), (3, 4)].to_interval_set()).is_empty());Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
* operator.Source§impl<'b, Bound: Num + Width> Mul<&'b IntervalSet<Bound>> for IntervalSet<Bound>
impl<'b, Bound: Num + Width> Mul<&'b IntervalSet<Bound>> for IntervalSet<Bound>
Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
* operator.Source§fn mul(self, other: &IntervalSet<Bound>) -> IntervalSet<Bound>
fn mul(self, other: &IntervalSet<Bound>) -> IntervalSet<Bound>
* operation. Read moreSource§impl<'a, Bound: Num + Width + Clone> Mul<Bound> for &'a IntervalSet<Bound>
impl<'a, Bound: Num + Width + Clone> Mul<Bound> for &'a IntervalSet<Bound>
Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
* operator.Source§fn mul(self, other: Bound) -> IntervalSet<Bound>
fn mul(self, other: Bound) -> IntervalSet<Bound>
* operation. Read moreSource§impl<Bound: Num + Width + Clone> Mul<Bound> for IntervalSet<Bound>
impl<Bound: Num + Width + Clone> Mul<Bound> for IntervalSet<Bound>
Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
* operator.Source§fn mul(self, other: Bound) -> IntervalSet<Bound>
fn mul(self, other: Bound) -> IntervalSet<Bound>
* operation. Read moreSource§impl<'a, Bound: Num + Width> Mul<IntervalSet<Bound>> for &'a IntervalSet<Bound>
impl<'a, Bound: Num + Width> Mul<IntervalSet<Bound>> for &'a IntervalSet<Bound>
Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
* operator.Source§fn mul(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>
fn mul(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>
* operation. Read moreSource§impl<Bound: Num + Width> Mul for IntervalSet<Bound>
impl<Bound: Num + Width> Mul for IntervalSet<Bound>
Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
* operator.Source§fn mul(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>
fn mul(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>
* operation. Read moreSource§impl<Bound: Width + Num> Overlap<Bound> for IntervalSet<Bound>
impl<Bound: Width + Num> Overlap<Bound> for IntervalSet<Bound>
Source§fn overlap(&self, value: &Bound) -> bool
fn overlap(&self, value: &Bound) -> bool
Calculates whether a value is included in the interval set.
This returns the same result as the IntervalSet::contains
let interval_set = [(3, 5), (8, 9)].to_interval_set();
assert!(interval_set.overlap(&3));
assert!(interval_set.overlap(&8));
assert!(interval_set.overlap(&9));
assert!(!interval_set.overlap(&1));
assert!(!interval_set.overlap(&7));
assert!(!interval_set.overlap(&10));Source§impl Overlap<IntervalSet<i16>> for i16
impl Overlap<IntervalSet<i16>> for i16
Source§fn overlap(&self, other: &IntervalSet<i16>) -> bool
fn overlap(&self, other: &IntervalSet<i16>) -> bool
Calculates whether a value is included in an interval set.
let interval_set: IntervalSet<i16> = [(3, 5), (8, 9)].to_interval_set();
assert!((3 as i16).overlap(&interval_set));
assert!((8 as i16).overlap(&interval_set));
assert!((9 as i16).overlap(&interval_set));
///
assert!(!(1 as i16).overlap(&interval_set));
assert!(!(7 as i16).overlap(&interval_set));
assert!(!(10 as i16).overlap(&interval_set));Source§impl Overlap<IntervalSet<i32>> for i32
impl Overlap<IntervalSet<i32>> for i32
Source§fn overlap(&self, other: &IntervalSet<i32>) -> bool
fn overlap(&self, other: &IntervalSet<i32>) -> bool
Calculates whether a value is included in an interval set.
let interval_set: IntervalSet<i32> = [(3, 5), (8, 9)].to_interval_set();
assert!((3 as i32).overlap(&interval_set));
assert!((8 as i32).overlap(&interval_set));
assert!((9 as i32).overlap(&interval_set));
///
assert!(!(1 as i32).overlap(&interval_set));
assert!(!(7 as i32).overlap(&interval_set));
assert!(!(10 as i32).overlap(&interval_set));Source§impl Overlap<IntervalSet<i64>> for i64
impl Overlap<IntervalSet<i64>> for i64
Source§fn overlap(&self, other: &IntervalSet<i64>) -> bool
fn overlap(&self, other: &IntervalSet<i64>) -> bool
Calculates whether a value is included in an interval set.
let interval_set: IntervalSet<i64> = [(3, 5), (8, 9)].to_interval_set();
assert!((3 as i64).overlap(&interval_set));
assert!((8 as i64).overlap(&interval_set));
assert!((9 as i64).overlap(&interval_set));
///
assert!(!(1 as i64).overlap(&interval_set));
assert!(!(7 as i64).overlap(&interval_set));
assert!(!(10 as i64).overlap(&interval_set));Source§impl Overlap<IntervalSet<i8>> for i8
impl Overlap<IntervalSet<i8>> for i8
Source§fn overlap(&self, other: &IntervalSet<i8>) -> bool
fn overlap(&self, other: &IntervalSet<i8>) -> bool
Calculates whether a value is included in an interval set.
let interval_set: IntervalSet<i8> = [(3, 5), (8, 9)].to_interval_set();
assert!((3 as i8).overlap(&interval_set));
assert!((8 as i8).overlap(&interval_set));
assert!((9 as i8).overlap(&interval_set));
///
assert!(!(1 as i8).overlap(&interval_set));
assert!(!(7 as i8).overlap(&interval_set));
assert!(!(10 as i8).overlap(&interval_set));Source§impl Overlap<IntervalSet<isize>> for isize
impl Overlap<IntervalSet<isize>> for isize
Source§fn overlap(&self, other: &IntervalSet<isize>) -> bool
fn overlap(&self, other: &IntervalSet<isize>) -> bool
Calculates whether a value is included in an interval set.
let interval_set: IntervalSet<isize> = [(3, 5), (8, 9)].to_interval_set();
assert!((3 as isize).overlap(&interval_set));
assert!((8 as isize).overlap(&interval_set));
assert!((9 as isize).overlap(&interval_set));
///
assert!(!(1 as isize).overlap(&interval_set));
assert!(!(7 as isize).overlap(&interval_set));
assert!(!(10 as isize).overlap(&interval_set));Source§impl Overlap<IntervalSet<u16>> for u16
impl Overlap<IntervalSet<u16>> for u16
Source§fn overlap(&self, other: &IntervalSet<u16>) -> bool
fn overlap(&self, other: &IntervalSet<u16>) -> bool
Calculates whether a value is included in an interval set.
let interval_set: IntervalSet<u16> = [(3, 5), (8, 9)].to_interval_set();
assert!((3 as u16).overlap(&interval_set));
assert!((8 as u16).overlap(&interval_set));
assert!((9 as u16).overlap(&interval_set));
///
assert!(!(1 as u16).overlap(&interval_set));
assert!(!(7 as u16).overlap(&interval_set));
assert!(!(10 as u16).overlap(&interval_set));Source§impl Overlap<IntervalSet<u32>> for u32
impl Overlap<IntervalSet<u32>> for u32
Source§fn overlap(&self, other: &IntervalSet<u32>) -> bool
fn overlap(&self, other: &IntervalSet<u32>) -> bool
Calculates whether a value is included in an interval set.
let interval_set: IntervalSet<u32> = [(3, 5), (8, 9)].to_interval_set();
assert!((3 as u32).overlap(&interval_set));
assert!((8 as u32).overlap(&interval_set));
assert!((9 as u32).overlap(&interval_set));
///
assert!(!(1 as u32).overlap(&interval_set));
assert!(!(7 as u32).overlap(&interval_set));
assert!(!(10 as u32).overlap(&interval_set));Source§impl Overlap<IntervalSet<u64>> for u64
impl Overlap<IntervalSet<u64>> for u64
Source§fn overlap(&self, other: &IntervalSet<u64>) -> bool
fn overlap(&self, other: &IntervalSet<u64>) -> bool
Calculates whether a value is included in an interval set.
let interval_set: IntervalSet<u64> = [(3, 5), (8, 9)].to_interval_set();
assert!((3 as u64).overlap(&interval_set));
assert!((8 as u64).overlap(&interval_set));
assert!((9 as u64).overlap(&interval_set));
///
assert!(!(1 as u64).overlap(&interval_set));
assert!(!(7 as u64).overlap(&interval_set));
assert!(!(10 as u64).overlap(&interval_set));Source§impl Overlap<IntervalSet<u8>> for u8
impl Overlap<IntervalSet<u8>> for u8
Source§fn overlap(&self, other: &IntervalSet<u8>) -> bool
fn overlap(&self, other: &IntervalSet<u8>) -> bool
Calculates whether a value is included in an interval set.
let interval_set: IntervalSet<u8> = [(3, 5), (8, 9)].to_interval_set();
assert!((3 as u8).overlap(&interval_set));
assert!((8 as u8).overlap(&interval_set));
assert!((9 as u8).overlap(&interval_set));
///
assert!(!(1 as u8).overlap(&interval_set));
assert!(!(7 as u8).overlap(&interval_set));
assert!(!(10 as u8).overlap(&interval_set));Source§impl Overlap<IntervalSet<usize>> for usize
impl Overlap<IntervalSet<usize>> for usize
Source§fn overlap(&self, other: &IntervalSet<usize>) -> bool
fn overlap(&self, other: &IntervalSet<usize>) -> bool
Calculates whether a value is included in an interval set.
let interval_set: IntervalSet<usize> = [(3, 5), (8, 9)].to_interval_set();
assert!((3 as usize).overlap(&interval_set));
assert!((8 as usize).overlap(&interval_set));
assert!((9 as usize).overlap(&interval_set));
///
assert!(!(1 as usize).overlap(&interval_set));
assert!(!(7 as usize).overlap(&interval_set));
assert!(!(10 as usize).overlap(&interval_set));Source§impl<Bound: Width + Num> Overlap<Optional<Bound>> for IntervalSet<Bound>
impl<Bound: Width + Num> Overlap<Optional<Bound>> for IntervalSet<Bound>
Source§fn overlap(&self, value: &Optional<Bound>) -> bool
fn overlap(&self, value: &Optional<Bound>) -> bool
Calculates whether an optional value is included in the interval set.
If the optional empty, this returns false.
This returns the same result as the IntervalSet::contains
let interval_set = [(3, 5), (8, 9)].to_interval_set();
assert!(interval_set.overlap(&Optional::singleton(3)));
assert!(interval_set.overlap(&Optional::singleton(9)));
assert!(!interval_set.overlap(&Optional::singleton(1)));
assert!(!interval_set.overlap(&Optional::singleton(10)));
assert!(!interval_set.overlap(&Optional::empty()));Source§impl<Bound: Width + Num> Overlap for IntervalSet<Bound>
impl<Bound: Width + Num> Overlap for IntervalSet<Bound>
Source§fn overlap(&self, rhs: &IntervalSet<Bound>) -> bool
fn overlap(&self, rhs: &IntervalSet<Bound>) -> bool
Calculates whether two interval contain any shared values.
let a = [(1, 3), (7, 8)].to_interval_set();
let b = [(4, 6)].to_interval_set();
assert!(!a.overlap(&b));
assert!(!b.overlap(&a));
let a = [(1, 3)].to_interval_set();
let b = [(3, 4), (8, 10)].to_interval_set();
assert!(a.overlap(&b));
assert!(b.overlap(&a));Source§impl<Bound> PartialEq for IntervalSet<Bound>
impl<Bound> PartialEq for IntervalSet<Bound>
Source§fn eq(&self, other: &IntervalSet<Bound>) -> bool
fn eq(&self, other: &IntervalSet<Bound>) -> bool
let single_interval = [(1, 5)].to_interval_set();
let equivalent_interval = [(1, 2), (2, 5)].to_interval_set();
assert_eq!(single_interval, equivalent_interval);Empty intervals are the same as each other, but not non-empty intervals.
assert_eq!(IntervalSet::<usize>::empty(), IntervalSet::<usize>::empty());
assert_ne!(IntervalSet::empty(), [(2, 3), (8, 9)].to_interval_set());Source§impl<Bound: Width + Num> ProperSubset for IntervalSet<Bound>
impl<Bound: Width + Num> ProperSubset for IntervalSet<Bound>
Source§fn is_proper_subset(&self, other: &IntervalSet<Bound>) -> bool
fn is_proper_subset(&self, other: &IntervalSet<Bound>) -> bool
Calculates whether one interval set is contained in another, but they are not equal. The empty interval set is a proper subset of everything, except itself.
let interval_set = [(3, 3), (7, 8)].to_interval_set();
assert!(interval_set.is_proper_subset(&[(3, 8)].to_interval_set()));
assert!(interval_set.is_proper_subset(&[(3, 4), (7, 9)].to_interval_set()));
assert!(!interval_set.is_proper_subset(&interval_set));
assert!(!interval_set.is_proper_subset(&[(3, 3)].to_interval_set()));
assert!(!interval_set.is_proper_subset(&[(7, 9)].to_interval_set()));
assert!(!interval_set.is_proper_subset(&[(3, 3), (8, 9)].to_interval_set()));
assert!(IntervalSet::empty().is_proper_subset(&interval_set));
assert!(!IntervalSet::<usize>::empty().is_proper_subset(&IntervalSet::empty()));Source§impl<Bound> Range for IntervalSet<Bound>
impl<Bound> Range for IntervalSet<Bound>
Source§fn new(lb: Bound, ub: Bound) -> IntervalSet<Bound>
fn new(lb: Bound, ub: Bound) -> IntervalSet<Bound>
Constructs an interval set from a specified interval.
let interval = IntervalSet::new(2, 4);
assert!(interval.contains(&2));
assert!(interval.contains(&3));
assert!(interval.contains(&4));
assert!(!interval.contains(&1));
assert!(!interval.contains(&5));Constructing an empty interval set is done via the IntervalSet::empty() method.
let empty_interval = IntervalSet::<u16>::empty();Source§impl<Bound> Serialize for IntervalSet<Bound>
impl<Bound> Serialize for IntervalSet<Bound>
Source§impl<Bound: Width + Num> ShrinkLeft for IntervalSet<Bound>
impl<Bound: Width + Num> ShrinkLeft for IntervalSet<Bound>
Source§fn shrink_left(&self, lb: Bound) -> IntervalSet<Bound>
fn shrink_left(&self, lb: Bound) -> IntervalSet<Bound>
Updates the lower bound of an interval set to be greater than or equal to a value.
let interval_set = [(4, 5), (8, 8)].to_interval_set();
assert_eq!(interval_set.shrink_left(2), interval_set);
assert_eq!(interval_set.shrink_left(4), interval_set);
assert_eq!(interval_set.shrink_left(5), [(5, 5), (8, 8)].to_interval_set());
assert_eq!(interval_set.shrink_left(7), IntervalSet::singleton(8));
assert_eq!(interval_set.shrink_left(8), IntervalSet::singleton(8));
assert_eq!(interval_set.shrink_left(9), IntervalSet::empty());Source§impl<Bound: Width + Num> ShrinkRight for IntervalSet<Bound>
impl<Bound: Width + Num> ShrinkRight for IntervalSet<Bound>
Source§fn shrink_right(&self, ub: Bound) -> IntervalSet<Bound>
fn shrink_right(&self, ub: Bound) -> IntervalSet<Bound>
Updates the upper bound of an interval set to be less than or equal to a value.
let interval_set = [(3, 3), (7, 8)].to_interval_set();
assert_eq!(interval_set.shrink_right(9), interval_set);
assert_eq!(interval_set.shrink_right(8), interval_set);
assert_eq!(interval_set.shrink_right(7), [(3, 3), (7, 7)].to_interval_set());
assert_eq!(interval_set.shrink_right(6), IntervalSet::singleton(3));
assert_eq!(interval_set.shrink_right(3), IntervalSet::singleton(3));
assert_eq!(interval_set.shrink_right(2), IntervalSet::empty());Source§impl<Bound: Width + Num> Singleton for IntervalSet<Bound>
impl<Bound: Width + Num> Singleton for IntervalSet<Bound>
Source§fn singleton(x: Bound) -> IntervalSet<Bound>
fn singleton(x: Bound) -> IntervalSet<Bound>
Constructs an interval set containing a single value. This set contains a single interval with the same upper and lower bounds.
let interval_set_5 = IntervalSet::singleton(5);
assert_eq!(interval_set_5.size(), 1 as u32);
assert_eq!(interval_set_5.lower(), interval_set_5.upper());
assert!(interval_set_5.contains(&5));
assert!(!interval_set_5.is_empty());Source§impl<'a, 'b, Bound: Num + Width + Clone> Sub<&'b Bound> for &'a IntervalSet<Bound>
impl<'a, 'b, Bound: Num + Width + Clone> Sub<&'b Bound> for &'a IntervalSet<Bound>
Source§fn sub(self, other: &Bound) -> IntervalSet<Bound>
fn sub(self, other: &Bound) -> IntervalSet<Bound>
Subtracts a constant from an interval set.
assert_eq!([(3, 3), (7, 8)].to_interval_set() - 2, [(1, 1), (5, 6)].to_interval_set());This method preserves empty interval sets.
assert!((IntervalSet::empty() - 4).is_empty());It is not possible to substract an interval set from a constant.
let _ = 10 - IntervalSet::new(5, 9); // doesn't compileSource§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
- operator.Source§impl<'b, Bound: Num + Width + Clone> Sub<&'b Bound> for IntervalSet<Bound>
impl<'b, Bound: Num + Width + Clone> Sub<&'b Bound> for IntervalSet<Bound>
Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
- operator.Source§impl<'a, 'b, Bound: Num + Width> Sub<&'b IntervalSet<Bound>> for &'a IntervalSet<Bound>
impl<'a, 'b, Bound: Num + Width> Sub<&'b IntervalSet<Bound>> for &'a IntervalSet<Bound>
Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
- operator.Source§fn sub(self, other: &IntervalSet<Bound>) -> IntervalSet<Bound>
fn sub(self, other: &IntervalSet<Bound>) -> IntervalSet<Bound>
- operation. Read moreSource§impl<'b, Bound: Num + Width> Sub<&'b IntervalSet<Bound>> for IntervalSet<Bound>
impl<'b, Bound: Num + Width> Sub<&'b IntervalSet<Bound>> for IntervalSet<Bound>
Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
- operator.Source§fn sub(self, other: &IntervalSet<Bound>) -> IntervalSet<Bound>
fn sub(self, other: &IntervalSet<Bound>) -> IntervalSet<Bound>
- operation. Read moreSource§impl<'a, Bound: Num + Width + Clone> Sub<Bound> for &'a IntervalSet<Bound>
impl<'a, Bound: Num + Width + Clone> Sub<Bound> for &'a IntervalSet<Bound>
Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
- operator.Source§fn sub(self, other: Bound) -> IntervalSet<Bound>
fn sub(self, other: Bound) -> IntervalSet<Bound>
- operation. Read moreSource§impl<Bound: Num + Width + Clone> Sub<Bound> for IntervalSet<Bound>
impl<Bound: Num + Width + Clone> Sub<Bound> for IntervalSet<Bound>
Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
- operator.Source§fn sub(self, other: Bound) -> IntervalSet<Bound>
fn sub(self, other: Bound) -> IntervalSet<Bound>
- operation. Read moreSource§impl<'a, Bound: Num + Width> Sub<IntervalSet<Bound>> for &'a IntervalSet<Bound>
impl<'a, Bound: Num + Width> Sub<IntervalSet<Bound>> for &'a IntervalSet<Bound>
Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
- operator.Source§fn sub(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>
fn sub(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>
- operation. Read moreSource§impl<Bound: Num + Width> Sub for IntervalSet<Bound>
impl<Bound: Num + Width> Sub for IntervalSet<Bound>
Source§type Output = IntervalSet<Bound>
type Output = IntervalSet<Bound>
- operator.Source§fn sub(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>
fn sub(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>
- operation. Read moreSource§impl<Bound: Width + Num> Subset for IntervalSet<Bound>
impl<Bound: Width + Num> Subset for IntervalSet<Bound>
Source§fn is_subset(&self, other: &IntervalSet<Bound>) -> bool
fn is_subset(&self, other: &IntervalSet<Bound>) -> bool
Calculates whether one interval set is contained in another. The empty interval set is a subset of everything.
let interval_set = [(3, 3), (7, 8)].to_interval_set();
assert!(interval_set.is_subset(&[(3, 8)].to_interval_set()));
assert!(interval_set.is_subset(&[(3, 4), (7, 9)].to_interval_set()));
assert!(interval_set.is_subset(&interval_set));
assert!(!interval_set.is_subset(&[(3, 3)].to_interval_set()));
assert!(!interval_set.is_subset(&[(7, 9)].to_interval_set()));
assert!(!interval_set.is_subset(&[(3, 3), (8, 9)].to_interval_set()));
assert!(IntervalSet::<usize>::empty().is_subset(&IntervalSet::empty()));
assert!(IntervalSet::empty().is_subset(&interval_set));Source§impl<Bound> SymmetricDifference<Bound> for IntervalSet<Bound>
impl<Bound> SymmetricDifference<Bound> for IntervalSet<Bound>
Source§fn symmetric_difference(&self, rhs: &Bound) -> IntervalSet<Bound>
fn symmetric_difference(&self, rhs: &Bound) -> IntervalSet<Bound>
If the value is in the interval set, this return the interval set without the value. If the value is not in the interval set, this returns the interval set extended with the value.
let interval_set = [(1, 3), (5, 9)].to_interval_set();
assert_eq!(interval_set.symmetric_difference(&4), [(1, 9)].to_interval_set());
assert_eq!(interval_set.symmetric_difference(&4), interval_set.union(&4));
assert_eq!(interval_set.symmetric_difference(&5), [(1, 3), (6, 9)].to_interval_set());
assert_eq!(interval_set.symmetric_difference(&5), interval_set.difference(&5));type Output = IntervalSet<Bound>
Source§impl<Bound: Width + Num> SymmetricDifference for IntervalSet<Bound>
impl<Bound: Width + Num> SymmetricDifference for IntervalSet<Bound>
Source§fn symmetric_difference(&self, rhs: &IntervalSet<Bound>) -> IntervalSet<Bound>
fn symmetric_difference(&self, rhs: &IntervalSet<Bound>) -> IntervalSet<Bound>
Calculates the interval set containing that are in either the left set or the right set, but not both.
let a = [(1, 3), (8, 8), (10, 11)].to_interval_set();
let b = [(2, 5), (7, 8), (12, 15)].to_interval_set();
let symmetric_difference = [(1, 1), (4, 5), (7, 7), (10, 15)].to_interval_set();
assert_eq!(a.symmetric_difference(&b), symmetric_difference);
assert_eq!(b.symmetric_difference(&a), symmetric_difference);
assert_eq!(IntervalSet::union(&a.difference(&b), &b.difference(&a)), symmetric_difference);type Output = IntervalSet<Bound>
Source§impl<Bound> Top for IntervalSet<Bound>
impl<Bound> Top for IntervalSet<Bound>
fn top() -> IntervalSet<Bound>
Source§impl<Bound> Union<Bound> for IntervalSet<Bound>
impl<Bound> Union<Bound> for IntervalSet<Bound>
Source§fn union(&self, rhs: &Bound) -> IntervalSet<Bound>
fn union(&self, rhs: &Bound) -> IntervalSet<Bound>
Adds a value to the interval set. The value does not have to below to an existing interval, but if it does, those intervals will be merged.
let interval_set = [(1, 4), (6, 7)].to_interval_set();
assert_eq!(interval_set.union(&10), [(1, 4), (6, 7), (10, 10)].to_interval_set());
assert_eq!(interval_set.union(&3), interval_set);
assert_eq!(interval_set.union(&6), interval_set);
assert_eq!(interval_set.union(&0), [(0, 4), (6, 7)].to_interval_set());
assert_eq!(interval_set.union(&8), [(1, 4), (6, 8)].to_interval_set());
assert_eq!(interval_set.union(&5), [(1, 7)].to_interval_set());type Output = IntervalSet<Bound>
Source§impl<Bound: Width + Num> Union for IntervalSet<Bound>
impl<Bound: Width + Num> Union for IntervalSet<Bound>
Source§fn union(&self, rhs: &IntervalSet<Bound>) -> IntervalSet<Bound>
fn union(&self, rhs: &IntervalSet<Bound>) -> IntervalSet<Bound>
Calculates the union of two interval sets. This returns an interval set containing all the values in the two that were unified.
let a = [(1, 3), (8, 8), (10, 11)].to_interval_set();
let b = [(2, 5), (7, 8), (12, 15)].to_interval_set();
assert_eq!(a.union(&b), [(1, 5), (7, 8), (10, 15)].to_interval_set());type Output = IntervalSet<Bound>
Source§impl<Bound> Whole for IntervalSet<Bound>
impl<Bound> Whole for IntervalSet<Bound>
Source§fn whole() -> IntervalSet<Bound>
fn whole() -> IntervalSet<Bound>
Constructs an interval set using the entire range an interval can represent.
The bounds of the interval set are bounded in the same way as Interval::whole.
This is different for unsigned and signed integers:
let unsigned_interval = IntervalSet::<u8>::whole();
assert_eq!(unsigned_interval, IntervalSet::new(0, 254));
let signed_interval = IntervalSet::<i8>::whole();
assert_eq!(signed_interval, IntervalSet::new(-127, 127));impl<Bound: Width + Num> Eq for IntervalSet<Bound>
impl<Bound: Width> IntervalKind for IntervalSet<Bound>
Auto Trait Implementations§
impl<Bound> Freeze for IntervalSet<Bound>
impl<Bound> RefUnwindSafe for IntervalSet<Bound>
impl<Bound> Send for IntervalSet<Bound>
impl<Bound> Sync for IntervalSet<Bound>
impl<Bound> Unpin for IntervalSet<Bound>
impl<Bound> UnwindSafe for IntervalSet<Bound>
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§impl<R> IsSingleton for Rwhere
R: Cardinality,
impl<R> IsSingleton for Rwhere
R: Cardinality,
fn is_singleton(&self) -> bool
Source§impl<R> StrictEntailment for Rwhere
R: Entailment + Eq,
impl<R> StrictEntailment for Rwhere
R: Entailment + Eq,
Source§fn strict_entail(&self, other: &R) -> SKleene
fn strict_entail(&self, other: &R) -> SKleene
a.entail(&b) && a != b.