AtomicInterval

Struct AtomicInterval 

Source
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 interval
  • right - 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.

Source

pub fn open(left: T, right: T) -> Self

Creates an open interval (a,b) that excludes both endpoints.

§Arguments
  • left - The left endpoint of the interval
  • right - The right endpoint of the interval
§Returns

A new AtomicInterval with excluded endpoints

Source

pub fn closed(left: T, right: T) -> Self

Creates a closed interval [a,b] that includes both endpoints.

§Arguments
  • left - The left endpoint of the interval
  • right - The right endpoint of the interval
§Returns

A new AtomicInterval with included endpoints

Source

pub fn open_closed(left: T, right: T) -> Self

Creates a left-open, right-closed interval (a,b] that excludes the left endpoint and includes the right endpoint.

§Arguments
  • left - The left endpoint of the interval
  • right - The right endpoint of the interval
§Returns

A new AtomicInterval with excluded left endpoint and included right endpoint

Source

pub fn closed_open(left: T, right: T) -> Self

Creates a left-closed, right-open interval [a,b) that includes the left endpoint and excludes the right endpoint.

§Arguments
  • left - The left endpoint of the interval
  • right - The right endpoint of the interval
§Returns

A new AtomicInterval with included left endpoint and excluded right endpoint

Source

pub fn point(value: T) -> Self

Creates a point interval [a,a] containing a single value.

§Arguments
  • value - The value to create a point interval from
§Returns

A new AtomicInterval representing a single point

Source§

impl<T> AtomicInterval<T>

Source

pub fn left(&self) -> &Bound<T>

Return a reference to the left bound.

§Returns

A reference of Bound associated to the left bound.

Source

pub fn right(&self) -> &Bound<T>

Return a reference to the right bound.

§Returns

A reference of Bound associated to the right bound.

Source§

impl<T: PartialOrd> AtomicInterval<T>

A collection of methods for performing set operations on atomic intervals.

Source

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

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

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

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

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>

Source

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 union
  • b - 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));
Source

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

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>

Source§

fn clone(&self) -> AtomicInterval<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 AtomicInterval<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 AtomicInterval<T>

Source§

fn eq(&self, other: &AtomicInterval<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 AtomicInterval<T>

Implementation of the ToString trait for AtomicInterval.

Source§

fn to_string(&self) -> String

This allows AtomicInterval to be converted to a string.

§Returns

A string representation of the AtomicInterval

Source§

impl<T> StructuralPartialEq for AtomicInterval<T>

Auto Trait Implementations§

§

impl<T> Freeze for AtomicInterval<T>
where T: Freeze,

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for AtomicInterval<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.