pub struct Interval<T: Ord> { /* private fields */ }
Expand description

A utility data structure to represent intervals. It supports open, close and unbounded intervals

Examples

use store_interval_tree::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 interval
  • high: 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 store_interval_tree::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 point.

Arguments
  • value: value of the point
Examples
use store_interval_tree::Interval;
use std::ops::Bound::*;

// create point (2) or equivalently interval [2,2]
let point1 = Interval::point(2);

Creates a duplicate of the interval

Examples
use store_interval_tree::Interval;
use std::ops::Bound::*;

let interval = Interval::new(Included(2), Unbounded);
let duplicate = interval.duplicate();

assert!(interval == duplicate);

Get reference to lower bound of the interval

Get a duplicate of lower bound of the interval

Get reference to higher bound of the interval

Get a duplicate of higher bound of the interval

Returns true if first and second intervals overlap, false otherwise

Examples
use store_interval_tree::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 store_interval_tree::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 store_interval_tree::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);

Returns the span between the start and the end of the interval. None if the interval is unbounded.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
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
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.