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]
A: Array<Item = RangeInclusive<T>> + Eq + Debug,
T: PrimInt + Debug,
pub fn new() -> Self
[src]
New empty range set
pub fn with_capacity(capacity: usize) -> Self
[src]
New empty range set with the internal smallvec initialized with the given initial capacity
pub fn from_ranges(ranges: SmallVec<A>) -> Option<Self>
[src]
Returns a new range set if the given vector of ranges is valid
(valid_range_vec
)
pub fn is_empty(&self) -> bool
[src]
Check if range set is empty
pub fn clear(&mut self)
[src]
Clears the range set
pub fn into_smallvec(self) -> SmallVec<A>
[src]
Converts into the internal smallvec
pub fn insert(&mut self, element: T) -> bool
[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());
pub fn remove(&mut self, element: T) -> bool
[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());
pub fn insert_range(&mut self, range: A::Item) -> Option<Self>
[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);
pub fn remove_range(&mut self, range: A::Item) -> Option<Self>
[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>pub fn iter(&self) -> Iter<A, T>
[src]
pub fn valid_range_vec(ranges: &SmallVec<A>) -> bool
[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));
pub fn spilled(&self) -> bool
[src]
Calls spilled
on the underlying smallvec
pub fn shrink_to_fit(&mut self)
[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]
A: Array + Eq + Debug,
A::Item: Clone + Eq + Debug,
fn clone(&self) -> RangeSet<A>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
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]
A: Array + Eq + Debug,
A::Item: Clone + Eq + Debug,
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[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]
A: Array + Eq + Debug,
A::Item: Clone + Eq + Debug,
impl<A: PartialEq> PartialEq for RangeSet<A> where
A: Array + Eq + Debug,
A::Item: Clone + Eq + Debug,
[src]
A: Array + Eq + Debug,
A::Item: Clone + Eq + Debug,
fn eq(&self, __arg_0: &RangeSet<A>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &RangeSet<A>) -> bool
[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]
A: Array<Item = RangeInclusive<T>> + Eq + Debug,
T: PrimInt + Debug,
fn from(range: RangeInclusive<T>) -> Self
[src]
Performs the conversion.