Module interval::interval_set [−][src]
Expand description
Closed and bounded generic interval set.
It stores intervals in a set. The main advantage is the exact representation of an interval by allowing “holes”. For example [1..2] U [5..6]
is stored as {[1..2], [5..6]}
. This structure is more space-efficient than a classic set collection (such as BTreeSet
) if the data stored are mostly contiguous. Of course, it is less light-weight than interval, but we keep the list of intervals as small as possible by merging overlapping intervals.
extern crate gcollections;
extern crate interval;
use crate::interval::interval_set::*;
use gcollections::ops::*;
let a = vec![(1,2), (6,10)].to_interval_set();
let b = vec![(3,5), (7,7)].to_interval_set();
let a_union_b = vec![(1,5), (6,10)].to_interval_set();
let a_intersect_b = vec![(7,7)].to_interval_set();
assert_eq!(a.union(&b), a_union_b);
assert_eq!(a.intersection(&b), a_intersect_b);