pub struct AtomicInterval<T> { /* private fields */ }Expand description
A struct representing an atomic interval. An atomic interval is a closed or open interval that contains a single value or a range of values.
§Fields
left- The left endpoint of the intervalright- The right endpoint of the interval
§Examples
use timekeep_rs::{AtomicInterval, Bound};
let interval = AtomicInterval::closed(1, 5);
assert_eq!(*interval.left(), Bound::Included(1));
assert_eq!(*interval.right(), Bound::Included(5));Implementations§
Source§impl<T: Clone + PartialOrd> AtomicInterval<T>
A collection of constructors for creating different types of atomic intervals.
impl<T: Clone + PartialOrd> AtomicInterval<T>
A collection of constructors for creating different types of atomic intervals.
Sourcepub fn open_closed(left: T, right: T) -> Self
pub fn open_closed(left: T, right: T) -> Self
Sourcepub fn closed_open(left: T, right: T) -> Self
pub fn closed_open(left: T, right: T) -> Self
Source§impl<T> AtomicInterval<T>
impl<T> AtomicInterval<T>
Source§impl<T: PartialOrd> AtomicInterval<T>
A collection of methods for performing set operations on atomic intervals.
impl<T: PartialOrd> AtomicInterval<T>
A collection of methods for performing set operations on atomic intervals.
Sourcepub fn is_superset(&self, other: &AtomicInterval<T>) -> bool
pub fn is_superset(&self, other: &AtomicInterval<T>) -> bool
Checks if the interval is a superset of another interval. An interval is a superset of another if it contains all the elements of the other interval.
§Arguments
other- The other interval to check if it is a subset of the current interval
§Returns
true if the current interval is a superset of the other interval, false otherwise
§Examples
use timekeep_rs::AtomicInterval;
let interval1 = AtomicInterval::closed(1, 5);
let interval2 = AtomicInterval::closed(2, 4);
assert!(interval1.is_superset(&interval2));Sourcepub fn is_subset(&self, other: &AtomicInterval<T>) -> bool
pub fn is_subset(&self, other: &AtomicInterval<T>) -> bool
Checks if the interval is a subset of another interval. An interval is a subset of another if it is contained within the other interval.
§Arguments
other- The other interval to check if it is a superset of the current interval
§Returns
true if the current interval is a subset of the other interval, false otherwise
§Examples
use timekeep_rs::AtomicInterval;
let interval1 = AtomicInterval::closed(2, 4);
let interval2 = AtomicInterval::closed(1, 5);
assert!(interval1.is_subset(&interval2));Sourcepub fn is_overlapping(&self, other: &AtomicInterval<T>) -> bool
pub fn is_overlapping(&self, other: &AtomicInterval<T>) -> bool
Checks if the interval is overlapping with another interval. Two intervals are overlapping if they share at least one common point.
§Arguments
other- The other interval to check if it is overlapping with the current interval
§Returns
true if the current interval is overlapping with the other interval, false otherwise
§Examples
use timekeep_rs::AtomicInterval;
let interval1 = AtomicInterval::closed(1, 5);
let interval2 = AtomicInterval::closed(4, 6);
assert!(interval1.is_overlapping(&interval2));Sourcepub fn is_adjacent(&self, other: &AtomicInterval<T>) -> bool
pub fn is_adjacent(&self, other: &AtomicInterval<T>) -> bool
Checks if the interval is adjacent to another interval. Two intervals are adjacent if they share a common boundary, but do not overlap.
§Arguments
other- The other interval to check if it is adjacent to the current interval
§Returns
true if the current interval is adjacent to the other interval, false otherwise
§Examples
use timekeep_rs::AtomicInterval;
let interval1 = AtomicInterval::closed(1, 5);
let interval2 = AtomicInterval::open_closed(5, 10);
assert!(interval1.is_adjacent(&interval2));Sourcepub fn is_disjoint(&self, other: &AtomicInterval<T>) -> bool
pub fn is_disjoint(&self, other: &AtomicInterval<T>) -> bool
Checks if the interval is disjoint from another interval. Two intervals are disjoint if they do not share any common points.
§Arguments
other- The other interval to check if it is disjoint from the current interval
§Returns
true if the current interval is disjoint from the other interval, false otherwise
§Examples
use timekeep_rs::AtomicInterval;
let interval1 = AtomicInterval::closed(1, 5);
let interval2 = AtomicInterval::closed(6, 10);
assert!(interval1.is_disjoint(&interval2));Source§impl<T: PartialOrd + Clone> AtomicInterval<T>
impl<T: PartialOrd + Clone> AtomicInterval<T>
Sourcepub fn union(
a: &AtomicInterval<T>,
b: &AtomicInterval<T>,
) -> Vec<AtomicInterval<T>>
pub fn union( a: &AtomicInterval<T>, b: &AtomicInterval<T>, ) -> Vec<AtomicInterval<T>>
Computes the union of two overlapping or adjacent intervals. The union of two intervals is the smallest interval that contains both intervals.
§Arguments
a- The first interval to unionb- The second interval to union
§Returns
A Vec containing the union of the two intervals if they are overlapping or adjacent, an empty Vec otherwise
§Examples
use timekeep_rs::AtomicInterval;
let interval1 = AtomicInterval::closed(1, 5);
let interval2 = AtomicInterval::closed(4, 7);
let merged = AtomicInterval::union(&interval1, &interval2);
assert_eq!(merged.len(), 1);
assert_eq!(merged.first().unwrap(), &AtomicInterval::closed(1, 7));Sourcepub fn intersection(&self, other: &Self) -> Vec<Self>
pub fn intersection(&self, other: &Self) -> Vec<Self>
Computes the intersection of two overlapping intervals. The intersection of two intervals is the largest interval that is contained within both intervals.
§Arguments
other- The other interval to intersect with the current interval
§Returns
A Vec containing the intersection of the two intervals if they are overlapping, an empty Vec otherwise
§Examples
use timekeep_rs::AtomicInterval;
let interval1 = AtomicInterval::closed(1, 5);
let interval2 = AtomicInterval::closed(3, 7);
let intersection = interval1.intersection(&interval2);
assert_eq!(intersection.len(), 1);
assert_eq!(intersection.first().unwrap(), &AtomicInterval::closed(3, 5));Sourcepub fn difference(&self, other: &Self) -> Vec<Self>
pub fn difference(&self, other: &Self) -> Vec<Self>
Computes the difference between two intervals. The difference between two intervals is the set of intervals that are in the first interval but not in the second interval.
§Arguments
other- The other interval to compute the difference with the current interval
§Returns
A Vec of AtomicInterval representing the difference between the two intervals
§Examples
use timekeep_rs::AtomicInterval;
let interval1 = AtomicInterval::closed(1, 5);
let interval2 = AtomicInterval::closed(3, 7);
let difference = interval1.difference(&interval2);
assert_eq!(difference.len(), 1);
assert_eq!(difference[0], AtomicInterval::closed_open(1, 3));Trait Implementations§
Source§impl<T: Clone> Clone for AtomicInterval<T>
impl<T: Clone> Clone for AtomicInterval<T>
Source§fn clone(&self) -> AtomicInterval<T>
fn clone(&self) -> AtomicInterval<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 AtomicInterval<T>
impl<T: Debug> Debug for AtomicInterval<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();Source§impl<T: PartialEq> PartialEq for AtomicInterval<T>
impl<T: PartialEq> PartialEq for AtomicInterval<T>
Source§impl<T: ToString> ToString for AtomicInterval<T>
Implementation of the ToString trait for AtomicInterval.
impl<T: ToString> ToString for AtomicInterval<T>
Implementation of the ToString trait for AtomicInterval.