Struct range_set::RangeSet [] [src]

pub struct RangeSet<A> where
    A: Array + Eq + Debug,
    A::Item: Clone + Eq + Debug
{ /* fields omitted */ }

A set of primitive integers represented as a sorted list of disjoint, inclusive ranges.

let mut s = RangeSet::<[RangeInclusive <u32>; 1]>::from (0..=2);
println!("s: {:?}", s);
assert!(!s.spilled());

assert!(s.insert_range (8..=10).is_none());
println!("s: {:?}", s);
assert!(s.spilled());
let v : Vec <u32> = s.iter().collect();
assert_eq!(v, vec![0,1,2,8,9,10]);

assert_eq!(s.insert_range (3..=12), Some (RangeSet::from (8..=10)));
println!("s: {:?}", s);
assert!(s.spilled());  // once spilled, stays spilled
let v : Vec <u32> = s.iter().collect();
assert_eq!(v, vec![0,1,2,3,4,5,6,7,8,9,10,11,12]);
s.shrink_to_fit();  // manually un-spill
assert!(!s.spilled());

Methods

impl<A, T> RangeSet<A> where
    A: Array<Item = RangeInclusive<T>> + Eq + Debug,
    T: PrimInt + Debug
[src]

[src]

New empty range set

[src]

New empty range set with the internal smallvec initialized with the given initial capacity

[src]

Returns a new range set if the given vector of ranges is valid (valid_range_vec)

[src]

Check if range set is empty

[src]

Clears the range set

[src]

Converts into the internal smallvec

[src]

Insert a single element, returning true if it was successfully inserted or else false if it was already present

let mut s = RangeSet::<[RangeInclusive <u32>; 2]>::new();
assert!(s.insert (4));
assert_eq!(s, RangeSet::from (4..=4));
assert!(!s.insert (4));
assert_eq!(s, RangeSet::from (4..=4));
assert!(s.insert (5));
assert_eq!(s, RangeSet::from (4..=5));
assert!(s.insert (3));
assert_eq!(s, RangeSet::from (3..=5));
assert!(s.insert (10));
assert_eq!(s, RangeSet::from_ranges (vec![3..=5, 10..=10].into()).unwrap());

[src]

Remove a single element, returning true if it was successfully removed or else false if it was not present

let mut s = RangeSet::<[RangeInclusive <u32>; 2]>::from (0..=5);
assert!(s.remove (1));
assert_eq!(s, RangeSet::from_ranges (vec![0..=0, 2..=5].into()).unwrap());
assert!(!s.remove (1));
assert_eq!(s, RangeSet::from_ranges (vec![0..=0, 2..=5].into()).unwrap());
assert!(s.remove (4));
assert_eq!(s, RangeSet::from_ranges (vec![0..=0, 2..=3, 5..=5].into()).unwrap());
assert!(s.remove (3));
assert_eq!(s, RangeSet::from_ranges (vec![0..=0, 2..=2, 5..=5].into()).unwrap());
assert!(s.remove (2));
assert_eq!(s, RangeSet::from_ranges (vec![0..=0, 5..=5].into()).unwrap());
assert!(s.remove (0));
assert_eq!(s, RangeSet::from (5..=5));
assert!(s.remove (5));
assert!(s.is_empty());

[src]

Returns the intersected values if the range is not disjoint with the curret range set.

let mut s = RangeSet::<[RangeInclusive <u32>; 2]>::from (0..=5);
assert_eq!(s.insert_range ( 3..=10), Some (RangeSet::from (3..=5)));
assert_eq!(s.insert_range (20..=30), None);

[src]

Removes and returns the intersected elements, if there were any.

let mut s = RangeSet::<[RangeInclusive <u32>; 2]>::from (0..=5);
assert_eq!(s.remove_range (3..=3), Some (RangeSet::from (3..=3)));
assert_eq!(s, RangeSet::from_ranges (vec![0..=2, 4..=5].into()).unwrap());
assert_eq!(s.remove_range (0..=10), Some (
  RangeSet::from_ranges (vec![0..=2, 4..=5].into()).unwrap()));
assert!(s.is_empty());

Important traits for Iter<'a, A, T>
[src]

[src]

Tests a raw smallvec of ranges for validity as a range set: the element ranges must be properly disjoint (not adjacent) and sorted.

let mut v = SmallVec::<[RangeInclusive <u32>; 2]>::new();
assert!(RangeSet::valid_range_vec (&v));
v.push (0..=3);
assert!(RangeSet::valid_range_vec (&v));
v.push (6..=10);
assert!(RangeSet::valid_range_vec (&v));
v.push (0..=1);
assert!(!RangeSet::valid_range_vec (&v));

[src]

Calls spilled on the underlying smallvec

[src]

Calls shrink_to_fit on the underlying smallvec

Trait Implementations

impl<A: Clone> Clone for RangeSet<A> where
    A: Array + Eq + Debug,
    A::Item: Clone + Eq + Debug
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<A: Debug> Debug for RangeSet<A> where
    A: Array + Eq + Debug,
    A::Item: Clone + Eq + Debug
[src]

[src]

Formats the value using the given formatter. Read more

impl<A: Eq> Eq for RangeSet<A> where
    A: Array + Eq + Debug,
    A::Item: Clone + Eq + Debug
[src]

impl<A: PartialEq> PartialEq for RangeSet<A> where
    A: Array + Eq + Debug,
    A::Item: Clone + Eq + Debug
[src]

[src]

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

[src]

This method tests for !=.

impl<A, T> From<RangeInclusive<T>> for RangeSet<A> where
    A: Array<Item = RangeInclusive<T>> + Eq + Debug,
    T: PrimInt + Debug
[src]

[src]

Performs the conversion.

Auto Trait Implementations

impl<A> Send for RangeSet<A> where
    <A as Array>::Item: Send

impl<A> Sync for RangeSet<A> where
    A: Sync