Struct interval_set::interval_set::IntervalSet [] [src]

pub struct IntervalSet { /* fields omitted */ }

Struct IntervalSet representing a set of sorted not overllaping intervals. Be aware that the validity of the interval set is not checked.

Methods

impl IntervalSet
[src]

Function to create an empty interval set.

Return true if the interval is empty.

Return the union of two intervals.

Example

use interval_set::interval_set::ToIntervalSet;

let a = vec![(5, 10)].to_interval_set();
let b = vec![(15, 20)].to_interval_set();
a.union(b); // [5-10, 15-20]

Return the intersection of two intervals.

Example

use interval_set::interval_set::ToIntervalSet;

let a = vec![(5, 10)].to_interval_set();
let b = vec![(5, 10), (15, 20)].to_interval_set();
a.intersection(b); //[5-10]

Return the difference between two intervals.

Example

use interval_set::interval_set::ToIntervalSet;

let a = vec![(5, 10), (15, 20)].to_interval_set();
let b = vec![(5, 10)].to_interval_set();
a.difference(b); //[15-20]

Return the symetric difference of two intervals.

Example

use interval_set::interval_set::ToIntervalSet;

let a = vec![(5, 10), (15, 20)].to_interval_set();
let b = vec![(0, 10)].to_interval_set();
a.difference(b); //[0-5, 15-20]

Return the greater interval from the set. Note that the function return a cloned interval, so I will be easier to manipulate. Moreover, in the case where many intervals have the same size, the function will return the first element.

Example

use interval_set::interval_set::ToIntervalSet;
use interval_set::interval_set::IntervalSet;
use interval_set::interval_set::Interval;

let a = vec![(5, 10), (15, 25)].to_interval_set();
let b = vec![(5, 10), (15, 20)].to_interval_set();
let c = vec![(5, 10), (15, 20), (100, 1000)].to_interval_set();

assert_eq!(a.max().unwrap(), Interval::new(15, 25));
assert_eq!(b.max().unwrap(), Interval::new(5, 10));
assert_eq!(c.max().unwrap(), Interval::new(100, 1000));
assert_eq!(IntervalSet::empty().max(), None);

Return the size of the interval set. The sie is defined by the sum of the len of each intervals contained into the set.

Example

use interval_set::interval_set::ToIntervalSet;

let a = vec![(5, 10), (15, 20)].to_interval_set();
let b = vec![(0, 10), (15, 20)].to_interval_set();
assert_eq!(a.size(), 12);
assert_eq!(b.size(), 17);

Get an iterator over an IntervalSet

Example

use interval_set::interval_set::ToIntervalSet;

let a = vec![(5, 10), (15, 20)].to_interval_set();
for intv in a.iter() {
    let tuple = intv.as_tuple();
    println!("{}--{}", tuple.0, tuple.1);
}

Trait Implementations

impl Clone for IntervalSet
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for IntervalSet
[src]

Formats the value using the given formatter.

impl Eq for IntervalSet
[src]

impl PartialEq for IntervalSet
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Display for IntervalSet
[src]

Formats the value using the given formatter.