IntervalSet

Struct IntervalSet 

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

Source

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

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.

Source

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

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 intersect
  • None if 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);
Source

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>

Source§

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

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<T: Debug> Debug for IntervalSet<T>

Source§

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

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

impl<T: Clone> From<AtomicInterval<T>> for IntervalSet<T>

Source§

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 IntervalSet<T>

Source§

fn eq(&self, other: &IntervalSet<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
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<T: ToString> ToString for IntervalSet<T>

Source§

fn to_string(&self) -> String

Converts the interval set to a string representation.

§Examples
use timekeep_rs::AtomicInterval;
use timekeep_rs::IntervalSet;

let interval = IntervalSet::from(AtomicInterval::closed(1, 5));
assert_eq!(interval.to_string(), "[[1, 5]]");
Source§

impl<T> StructuralPartialEq for IntervalSet<T>

Auto Trait Implementations§

§

impl<T> Freeze for IntervalSet<T>

§

impl<T> RefUnwindSafe for IntervalSet<T>
where T: RefUnwindSafe,

§

impl<T> Send for IntervalSet<T>
where T: Send,

§

impl<T> Sync for IntervalSet<T>
where T: Sync,

§

impl<T> Unpin for IntervalSet<T>
where T: Unpin,

§

impl<T> UnwindSafe for IntervalSet<T>
where T: 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<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, 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.