IntervalSet

Struct IntervalSet 

Source
pub struct IntervalSet<Bound: Width> { /* private fields */ }

Implementations§

Source§

impl<Bound: Width> IntervalSet<Bound>

Source

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

Source

pub fn iter_mut(&mut self) -> IterMut<'_, Interval<Bound>>

Source§

impl<Bound> IntervalSet<Bound>
where Bound: Width + Num,

Source

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>

Source§

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 compile
Source§

type Output = IntervalSet<Bound>

The resulting type after applying the + operator.
Source§

impl<'b, Bound: Num + Width + Clone> Add<&'b Bound> for IntervalSet<Bound>

Source§

type Output = IntervalSet<Bound>

The resulting type after applying the + operator.
Source§

fn add(self, other: &Bound) -> IntervalSet<Bound>

Performs the + operation. Read more
Source§

impl<'a, 'b, Bound: Num + Width> Add<&'b IntervalSet<Bound>> for &'a IntervalSet<Bound>

Source§

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>

The resulting type after applying the + operator.
Source§

impl<'b, Bound: Num + Width> Add<&'b IntervalSet<Bound>> for IntervalSet<Bound>

Source§

type Output = IntervalSet<Bound>

The resulting type after applying the + operator.
Source§

fn add(self, other: &IntervalSet<Bound>) -> IntervalSet<Bound>

Performs the + operation. Read more
Source§

impl<'a, Bound: Num + Width + Clone> Add<Bound> for &'a IntervalSet<Bound>

Source§

type Output = IntervalSet<Bound>

The resulting type after applying the + operator.
Source§

fn add(self, other: Bound) -> IntervalSet<Bound>

Performs the + operation. Read more
Source§

impl<Bound: Num + Width + Clone> Add<Bound> for IntervalSet<Bound>

Source§

type Output = IntervalSet<Bound>

The resulting type after applying the + operator.
Source§

fn add(self, other: Bound) -> IntervalSet<Bound>

Performs the + operation. Read more
Source§

impl<'a, Bound: Num + Width> Add<IntervalSet<Bound>> for &'a IntervalSet<Bound>

Source§

type Output = IntervalSet<Bound>

The resulting type after applying the + operator.
Source§

fn add(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>

Performs the + operation. Read more
Source§

impl<Bound: Num + Width> Add for IntervalSet<Bound>

Source§

type Output = IntervalSet<Bound>

The resulting type after applying the + operator.
Source§

fn add(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>

Performs the + operation. Read more
Source§

impl<Bound> Bot for IntervalSet<Bound>
where Bound: Width + Num,

Source§

fn bot() -> IntervalSet<Bound>

Source§

impl<Bound> Bounded for IntervalSet<Bound>
where Bound: Width + Num + PartialOrd,

Source§

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

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.

Source§

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());
Source§

type Size = <Bound as Width>::Output

Source§

impl<Bound: Clone + Width> Clone for IntervalSet<Bound>
where Bound::Output: Clone,

Source§

fn clone(&self) -> IntervalSet<Bound>

Returns a duplicate 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<Bound: Width> Collection for IntervalSet<Bound>

Source§

type Item = Bound

Source§

impl<Bound: Width + Num> Complement for IntervalSet<Bound>

Source§

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>

Source§

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<Bound: Debug + Width> Debug for IntervalSet<Bound>
where Bound::Output: Debug,

Source§

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

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

impl<'de, Bound> Deserialize<'de> for IntervalSet<Bound>
where Bound: Width + Num + Deserialize<'de>,

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<Bound> Difference<Bound> for IntervalSet<Bound>
where Bound: Width + Num + Clone,

Source§

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());
Source§

type Output = IntervalSet<Bound>

Source§

impl<Bound: Width + Num> Difference for IntervalSet<Bound>

Source§

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());
Source§

type Output = IntervalSet<Bound>

Source§

impl<Bound: Width + Num> Disjoint for IntervalSet<Bound>

Source§

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>
where <Bound as Width>::Output: Display,

Source§

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>

Source§

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>
where Bound: Width + Num,

Source§

fn entail(&self, other: &IntervalSet<Bound>) -> SKleene

Source§

impl<Bound> Extend<Interval<Bound>> for IntervalSet<Bound>
where Bound: Width + Num,

Source§

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)

🔬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<Bound> Intersection<Bound> for IntervalSet<Bound>
where Bound: Width + Num + Clone,

Source§

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));
Source§

type Output = IntervalSet<Bound>

Source§

impl<Bound: Width + Num> Intersection for IntervalSet<Bound>

Source§

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());
Source§

type Output = IntervalSet<Bound>

Source§

impl<'a, Bound: Width> IntoIterator for &'a IntervalSet<Bound>

Source§

type Item = &'a Interval<Bound>

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, Interval<Bound>>

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<'a, Bound: Width> IntoIterator for &'a mut IntervalSet<Bound>

Source§

type Item = &'a mut Interval<Bound>

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, Interval<Bound>>

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<Bound: Width> IntoIterator for IntervalSet<Bound>

Source§

type Item = Interval<Bound>

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<IntervalSet<Bound> as IntoIterator>::Item>

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<Bound> Join for IntervalSet<Bound>
where Bound: Width + Num,

Source§

fn join(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>

Source§

impl<Bound> Meet for IntervalSet<Bound>
where Bound: Width + Num,

Source§

fn meet(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>

Source§

impl<'a, 'b, Bound: Num + Width + Clone> Mul<&'b Bound> for &'a IntervalSet<Bound>

Source§

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 compile
Source§

type Output = IntervalSet<Bound>

The resulting type after applying the * operator.
Source§

impl<'b, Bound: Num + Width + Clone> Mul<&'b Bound> for IntervalSet<Bound>

Source§

type Output = IntervalSet<Bound>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &Bound) -> IntervalSet<Bound>

Performs the * operation. Read more
Source§

impl<'a, 'b, Bound: Num + Width> Mul<&'b IntervalSet<Bound>> for &'a IntervalSet<Bound>

Source§

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>

The resulting type after applying the * operator.
Source§

impl<'b, Bound: Num + Width> Mul<&'b IntervalSet<Bound>> for IntervalSet<Bound>

Source§

type Output = IntervalSet<Bound>

The resulting type after applying the * operator.
Source§

fn mul(self, other: &IntervalSet<Bound>) -> IntervalSet<Bound>

Performs the * operation. Read more
Source§

impl<'a, Bound: Num + Width + Clone> Mul<Bound> for &'a IntervalSet<Bound>

Source§

type Output = IntervalSet<Bound>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Bound) -> IntervalSet<Bound>

Performs the * operation. Read more
Source§

impl<Bound: Num + Width + Clone> Mul<Bound> for IntervalSet<Bound>

Source§

type Output = IntervalSet<Bound>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Bound) -> IntervalSet<Bound>

Performs the * operation. Read more
Source§

impl<'a, Bound: Num + Width> Mul<IntervalSet<Bound>> for &'a IntervalSet<Bound>

Source§

type Output = IntervalSet<Bound>

The resulting type after applying the * operator.
Source§

fn mul(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>

Performs the * operation. Read more
Source§

impl<Bound: Num + Width> Mul for IntervalSet<Bound>

Source§

type Output = IntervalSet<Bound>

The resulting type after applying the * operator.
Source§

fn mul(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>

Performs the * operation. Read more
Source§

impl<Bound: Width + Num> Overlap<Bound> for IntervalSet<Bound>

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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>

Source§

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>

Source§

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>
where Bound: Width + Num,

Source§

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());
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<Bound: Width + Num> ProperSubset for IntervalSet<Bound>

Source§

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>
where Bound: Width + Num,

Source§

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>
where Bound: Width + Num + Serialize, Interval<Bound>: Serialize,

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<Bound: Width + Num> ShrinkLeft for IntervalSet<Bound>
where <Bound as Width>::Output: Clone,

Source§

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>
where <Bound as Width>::Output: Clone,

Source§

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>

Source§

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>

Source§

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 compile
Source§

type Output = IntervalSet<Bound>

The resulting type after applying the - operator.
Source§

impl<'b, Bound: Num + Width + Clone> Sub<&'b Bound> for IntervalSet<Bound>

Source§

type Output = IntervalSet<Bound>

The resulting type after applying the - operator.
Source§

fn sub(self, other: &Bound) -> IntervalSet<Bound>

Performs the - operation. Read more
Source§

impl<'a, 'b, Bound: Num + Width> Sub<&'b IntervalSet<Bound>> for &'a IntervalSet<Bound>

Source§

type Output = IntervalSet<Bound>

The resulting type after applying the - operator.
Source§

fn sub(self, other: &IntervalSet<Bound>) -> IntervalSet<Bound>

Performs the - operation. Read more
Source§

impl<'b, Bound: Num + Width> Sub<&'b IntervalSet<Bound>> for IntervalSet<Bound>

Source§

type Output = IntervalSet<Bound>

The resulting type after applying the - operator.
Source§

fn sub(self, other: &IntervalSet<Bound>) -> IntervalSet<Bound>

Performs the - operation. Read more
Source§

impl<'a, Bound: Num + Width + Clone> Sub<Bound> for &'a IntervalSet<Bound>

Source§

type Output = IntervalSet<Bound>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Bound) -> IntervalSet<Bound>

Performs the - operation. Read more
Source§

impl<Bound: Num + Width + Clone> Sub<Bound> for IntervalSet<Bound>

Source§

type Output = IntervalSet<Bound>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Bound) -> IntervalSet<Bound>

Performs the - operation. Read more
Source§

impl<'a, Bound: Num + Width> Sub<IntervalSet<Bound>> for &'a IntervalSet<Bound>

Source§

type Output = IntervalSet<Bound>

The resulting type after applying the - operator.
Source§

fn sub(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>

Performs the - operation. Read more
Source§

impl<Bound: Num + Width> Sub for IntervalSet<Bound>

Source§

type Output = IntervalSet<Bound>

The resulting type after applying the - operator.
Source§

fn sub(self, other: IntervalSet<Bound>) -> IntervalSet<Bound>

Performs the - operation. Read more
Source§

impl<Bound: Width + Num> Subset for IntervalSet<Bound>

Source§

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>
where Bound: Width + Num + Clone,

Source§

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));
Source§

type Output = IntervalSet<Bound>

Source§

impl<Bound: Width + Num> SymmetricDifference for IntervalSet<Bound>

Source§

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);
Source§

type Output = IntervalSet<Bound>

Source§

impl<Bound> Top for IntervalSet<Bound>
where Bound: Width + Num,

Source§

fn top() -> IntervalSet<Bound>

Source§

impl<Bound> Union<Bound> for IntervalSet<Bound>
where Bound: Width + Num + Clone,

Source§

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());
Source§

type Output = IntervalSet<Bound>

Source§

impl<Bound: Width + Num> Union for IntervalSet<Bound>

Source§

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());
Source§

type Output = IntervalSet<Bound>

Source§

impl<Bound> Whole for IntervalSet<Bound>
where Bound: Width + Num,

Source§

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));
Source§

impl<Bound: Width + Num> Eq for IntervalSet<Bound>

Source§

impl<Bound: Width> IntervalKind for IntervalSet<Bound>

Auto Trait Implementations§

§

impl<Bound> Freeze for IntervalSet<Bound>
where <Bound as Width>::Output: Freeze,

§

impl<Bound> RefUnwindSafe for IntervalSet<Bound>
where <Bound as Width>::Output: RefUnwindSafe, Bound: RefUnwindSafe,

§

impl<Bound> Send for IntervalSet<Bound>
where <Bound as Width>::Output: Send, Bound: Send,

§

impl<Bound> Sync for IntervalSet<Bound>
where <Bound as Width>::Output: Sync, Bound: Sync,

§

impl<Bound> Unpin for IntervalSet<Bound>
where <Bound as Width>::Output: Unpin, Bound: Unpin,

§

impl<Bound> UnwindSafe for IntervalSet<Bound>
where <Bound as Width>::Output: UnwindSafe, Bound: UnwindSafe,

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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<R> IsEmpty for R
where R: Cardinality,

Source§

fn is_empty(&self) -> bool

Source§

impl<R> IsSingleton for R
where R: Cardinality,

Source§

impl<R> StrictEntailment for R
where R: Entailment + Eq,

Source§

fn strict_entail(&self, other: &R) -> SKleene

Must be similar to a.entail(&b) && a != b.
Source§

impl<B, R> StrictShrinkLeft for R
where R: ShrinkLeft<Item = B> + Empty + IntervalKind + Bounded, B: Integer + Bounded,

Source§

fn strict_shrink_left(&self, lb: B) -> R

Source§

impl<B, R> StrictShrinkRight for R
where R: ShrinkRight<Item = B> + Empty + IntervalKind + Bounded, B: Integer + Bounded,

Source§

fn strict_shrink_right(&self, ub: B) -> R

Source§

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

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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>,

Source§

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.
Source§

impl<R> BoundedLattice for R
where R: Lattice + Top + Bot,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<R> Lattice for R
where R: Join + Meet + Entailment,