Struct rudac::util::Interval [−][src]
pub struct Interval<T: Ord> { /* fields omitted */ }
Expand description
A utility data structure to represent intervals. It supports open, close and unbounded intervals
Examples
use rudac::util::Interval;
use std::ops::Bound::*;
// initialize interval [2,4]
let interval1 = Interval::new(Included(2), Included(4));
// initialize interval [2,4)
let interval2 = Interval::new(Included(2), Excluded(4));
// initialize point [4,4]
let point1 = Interval::point(4);
// compare intervals
// first, lower bounds are compared. if they're equal, higher bounds will be compared
assert!(interval2 < interval1);
// check if two intervals overlap
assert!(Interval::overlaps(&interval1, &interval2));
// check if one point and an interval overlap
assert!(Interval::overlaps(&interval1, &point1));
assert!(!Interval::overlaps(&interval2, &point1));
// check if one interval contains another interval
assert!(Interval::contains(&interval1, &interval2));
// get overlapped interval between two intervals
assert!(Interval::get_overlap(&interval1, &interval2).unwrap() == interval2);
Implementations
Creates a new interval
Arguments
low
: lower bound of the intervalhigh
: higher bound of the interval
Panics
- panics if
low
>high
.low
==high
is acceptable if interval is closed at both sides: [low, high]
Example
use rudac::util::Interval;
use std::ops::Bound::*;
// create the interval [2,4)
let interval1 = Interval::new(Included(2), Excluded(4));
// create the interval (-inf,4)
let interval2 = Interval::new(Unbounded, Excluded(4));
// create the interval (1,+inf)
let interval3 = Interval::new(Excluded(1), Unbounded);
Creates a duplicate of the interval
Examples
use rudac::util::Interval;
use std::ops::Bound::*;
let interval = Interval::new(Included(2), Unbounded);
let duplicate = interval.duplicate();
assert!(interval == duplicate);
Returns true if first
and second
intervals overlap, false otherwise
Examples
use rudac::util::Interval;
use std::ops::Bound::*;
let interval1 = Interval::new(Included(2), Included(4));
let interval2 = Interval::new(Included(2), Excluded(4));
let point1 = Interval::point(4);
assert!(Interval::overlaps(&interval1, &interval2));
assert!(Interval::overlaps(&interval1, &point1));
assert!(!Interval::overlaps(&interval2, &point1));
Returns true if second
is a sub-interval of first
, false otherwise
Examples
use rudac::util::Interval;
use std::ops::Bound::*;
let interval1 = Interval::new(Included(2), Included(4));
let interval2 = Interval::new(Included(2), Excluded(4));
assert!(Interval::contains(&interval1, &interval2));
Get overlapped interval of first
and second
, None
otherwise
Examples
use rudac::util::Interval;
use std::ops::Bound::*;
// initialize intervals
let interval1 = Interval::new(Included(2), Included(4));
let interval2 = Interval::new(Included(2), Excluded(4));
assert!(Interval::get_overlap(&interval1, &interval2).unwrap() == interval2);
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more