pub struct IntervalSet<T> {
pub intervals: Vec<AtomicInterval<T>>,
}Fields§
§intervals: Vec<AtomicInterval<T>>A vector of AtomicIntervals that make up the IntervalSet
Implementations§
Source§impl<T: Clone> IntervalSet<T>
impl<T: Clone> IntervalSet<T>
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if this interval set has no intervals or is empty.
§Examples
use timekeep_rs::IntervalSet;
// Suppose `interval` is an `Interval` with no intervals.
let interval = IntervalSet::<i32> { intervals: vec![] };
assert!(interval.is_empty());Sourcepub fn new() -> IntervalSet<T>
pub fn new() -> IntervalSet<T>
Returns an empty IntervalSet.
§Examples
use timekeep_rs::IntervalSet;
// Suppose `interval` is an `Interval` with no intervals.
let interval = IntervalSet::<i32>::new();
assert!(interval.is_empty());Source§impl<T: PartialOrd + Clone> IntervalSet<T>
A trait implementation for IntervalSet<T> where T implements PartialOrd and Clone.
Provides set operations for interval sets.
impl<T: PartialOrd + Clone> IntervalSet<T>
A trait implementation for IntervalSet<T> where T implements PartialOrd and Clone.
Provides set operations for interval sets.
Sourcepub fn union(&self, other: &Self) -> Self
pub fn union(&self, other: &Self) -> Self
Computes the union of two interval sets.
The union of two interval sets is a new interval set that contains all the intervals from both input sets, merging any overlapping or adjacent intervals.
§Arguments
other- Another interval set to compute the union with
§Returns
A new IntervalSet<T> representing the union of both interval sets
§Examples
use timekeep_rs::AtomicInterval;
use timekeep_rs::IntervalSet;
// Create two interval sets
let interval1 = IntervalSet::from(AtomicInterval::closed(1, 5));
let interval2 = IntervalSet::from(AtomicInterval::closed(3, 7));
// Compute union (results in [1, 7])
let union = interval1.union(&interval2);Sourcepub fn intersection(&self, other: &Self) -> Self
pub fn intersection(&self, other: &Self) -> Self
Computes the intersection of two interval sets.
The intersection of two interval sets is a new interval set that contains all the intervals that are common to both input sets.
§Arguments
other- Another interval set to compute the intersection with
§Returns
Some(IntervalSet<T>)if the interval sets intersectNoneif the interval sets are disjoint
§Examples
use timekeep_rs::AtomicInterval;
use timekeep_rs::IntervalSet;
// Create two interval sets
let interval1 = IntervalSet::from(AtomicInterval::closed(1, 5));
let interval2 = IntervalSet::from(AtomicInterval::closed(3, 7));
// Compute intersection (results in [3, 5])
let intersection = interval1.intersection(&interval2);Sourcepub fn difference(&self, other: &Self) -> Self
pub fn difference(&self, other: &Self) -> Self
Computes the difference between two interval sets.
The difference A - B contains all points that are in A but not in B.
§Arguments
other- Another interval set to subtract from this interval set
§Returns
A new IntervalSet<T> representing the difference between the interval sets
§Examples
use timekeep_rs::AtomicInterval;
use timekeep_rs::IntervalSet;
// Create two interval sets
let interval1 = IntervalSet::from(AtomicInterval::closed(1, 5));
let interval2 = IntervalSet::from(AtomicInterval::closed(3, 7));
// Compute difference (results in [1, 3))
let difference = interval1.difference(&interval2);Trait Implementations§
Source§impl<T: Clone> Clone for IntervalSet<T>
impl<T: Clone> Clone for IntervalSet<T>
Source§fn clone(&self) -> IntervalSet<T>
fn clone(&self) -> IntervalSet<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug> Debug for IntervalSet<T>
impl<T: Debug> Debug for IntervalSet<T>
Source§impl<T: Clone> From<AtomicInterval<T>> for IntervalSet<T>
impl<T: Clone> From<AtomicInterval<T>> for IntervalSet<T>
Source§fn from(interval: AtomicInterval<T>) -> Self
fn from(interval: AtomicInterval<T>) -> Self
Creates a new IntervalSet<T> from an AtomicInterval<T>.
This implementation allows converting a single atomic interval into an IntervalSet<T>
collection by wrapping it in a vector.
§Examples
use timekeep_rs::AtomicInterval;
use timekeep_rs::IntervalSet;
let atomic = AtomicInterval::closed(1, 5);
let interval: IntervalSet<i32> = atomic.into();