pub struct RangeSet<T> { /* private fields */ }Expand description
A set of values represented using ranges.
A RangeSet is similar to any other kind of set, such as HashSet, with the difference being that the
values in the set are represented using ranges rather than storing each value individually.
§Invariants
RangeSet enforces the following invariants on the ranges it contains:
- The ranges are sorted.
- The ranges are non-adjacent.
- The ranges are non-intersecting.
- The ranges are non-empty.
This is enforced in the constructor, and guaranteed to hold after applying any operation on a range or set.
§Examples
use rangeset::*;
let a = 10..20;
// Difference
assert_eq!(a.difference(&(15..25)), RangeSet::from([10..15]));
assert_eq!(a.difference(&(12..15)), RangeSet::from([(10..12), (15..20)]));
// Union
assert_eq!(a.union(&(15..25)), RangeSet::from([10..25]));
assert_eq!(a.union(&(0..0)), RangeSet::from([10..20]));
// Comparison
assert!(a.is_subset(&(0..30)));
assert!(a.is_disjoint(&(0..10)));
assert_eq!(a.clone(), RangeSet::from(a));Implementations§
Source§impl<T: Copy + Ord> RangeSet<T>
impl<T: Copy + Ord> RangeSet<T>
Sourcepub fn new(ranges: &[Range<T>]) -> Self
pub fn new(ranges: &[Range<T>]) -> Self
Returns a new RangeSet from the given ranges.
The RangeSet is constructed by computing the union of the given ranges.
Sourcepub fn iter(&self) -> RangeSetIter<'_, T> ⓘ
pub fn iter(&self) -> RangeSetIter<'_, T> ⓘ
Returns an iterator over the values in the set.
Sourcepub fn iter_ranges(&self) -> RangeIter<'_, T> ⓘ
pub fn iter_ranges(&self) -> RangeIter<'_, T> ⓘ
Returns an iterator over the ranges in the set.
Source§impl<T: Copy + Ord + Step + Sub<Output = T>> RangeSet<T>
impl<T: Copy + Ord + Step + Sub<Output = T>> RangeSet<T>
Source§impl<T: Copy + Ord + Sub<Output = T>> RangeSet<T>
impl<T: Copy + Ord + Sub<Output = T>> RangeSet<T>
Sourcepub fn shift_left(&mut self, offset: &T)
pub fn shift_left(&mut self, offset: &T)
Shifts every range in the set to the left by the provided offset.
§Panics
Panics if the shift causes an underflow.
Trait Implementations§
Source§impl<T: Copy + Ord> BitAndAssign<&Range<T>> for RangeSet<T>
impl<T: Copy + Ord> BitAndAssign<&Range<T>> for RangeSet<T>
Source§fn bitand_assign(&mut self, other: &Range<T>)
fn bitand_assign(&mut self, other: &Range<T>)
Performs the
&= operation. Read moreSource§impl<T: Copy + Ord> BitAndAssign<&RangeSet<T>> for RangeSet<T>
impl<T: Copy + Ord> BitAndAssign<&RangeSet<T>> for RangeSet<T>
Source§fn bitand_assign(&mut self, other: &RangeSet<T>)
fn bitand_assign(&mut self, other: &RangeSet<T>)
Performs the
&= operation. Read moreSource§impl<T: Copy + Ord> BitAndAssign<Range<T>> for RangeSet<T>
impl<T: Copy + Ord> BitAndAssign<Range<T>> for RangeSet<T>
Source§fn bitand_assign(&mut self, other: Range<T>)
fn bitand_assign(&mut self, other: Range<T>)
Performs the
&= operation. Read moreSource§impl<T: Copy + Ord> BitAndAssign for RangeSet<T>
impl<T: Copy + Ord> BitAndAssign for RangeSet<T>
Source§fn bitand_assign(&mut self, other: RangeSet<T>)
fn bitand_assign(&mut self, other: RangeSet<T>)
Performs the
&= operation. Read moreSource§impl<T: Copy + Ord> BitOrAssign<&Range<T>> for RangeSet<T>
impl<T: Copy + Ord> BitOrAssign<&Range<T>> for RangeSet<T>
Source§fn bitor_assign(&mut self, other: &Range<T>)
fn bitor_assign(&mut self, other: &Range<T>)
Performs the
|= operation. Read moreSource§impl<T: Copy + Ord> BitOrAssign<&RangeSet<T>> for RangeSet<T>
impl<T: Copy + Ord> BitOrAssign<&RangeSet<T>> for RangeSet<T>
Source§fn bitor_assign(&mut self, other: &RangeSet<T>)
fn bitor_assign(&mut self, other: &RangeSet<T>)
Performs the
|= operation. Read moreSource§impl<T: Copy + Ord> BitOrAssign<Range<T>> for RangeSet<T>
impl<T: Copy + Ord> BitOrAssign<Range<T>> for RangeSet<T>
Source§fn bitor_assign(&mut self, other: Range<T>)
fn bitor_assign(&mut self, other: Range<T>)
Performs the
|= operation. Read moreSource§impl<T: Copy + Ord> BitOrAssign for RangeSet<T>
impl<T: Copy + Ord> BitOrAssign for RangeSet<T>
Source§fn bitor_assign(&mut self, other: RangeSet<T>)
fn bitor_assign(&mut self, other: RangeSet<T>)
Performs the
|= operation. Read moreSource§impl<T: Copy + Ord> BitXorAssign<&RangeSet<T>> for RangeSet<T>
impl<T: Copy + Ord> BitXorAssign<&RangeSet<T>> for RangeSet<T>
Source§fn bitxor_assign(&mut self, rhs: &RangeSet<T>)
fn bitxor_assign(&mut self, rhs: &RangeSet<T>)
Performs the
^= operation. Read moreSource§impl<T: Copy + Ord> BitXorAssign for RangeSet<T>
impl<T: Copy + Ord> BitXorAssign for RangeSet<T>
Source§fn bitxor_assign(&mut self, rhs: RangeSet<T>)
fn bitxor_assign(&mut self, rhs: RangeSet<T>)
Performs the
^= operation. Read moreSource§impl<T> Cover<RangeSet<T>> for RangeSet<T>
impl<T> Cover<RangeSet<T>> for RangeSet<T>
Source§impl<T: Copy + Ord> DifferenceMut<Range<T>> for RangeSet<T>
impl<T: Copy + Ord> DifferenceMut<Range<T>> for RangeSet<T>
Source§fn difference_mut(&mut self, other: &Range<T>)
fn difference_mut(&mut self, other: &Range<T>)
Subtracts
other from self.Source§impl<T: Copy + Ord> DifferenceMut<RangeSet<T>> for RangeSet<T>
impl<T: Copy + Ord> DifferenceMut<RangeSet<T>> for RangeSet<T>
Source§fn difference_mut(&mut self, other: &RangeSet<T>)
fn difference_mut(&mut self, other: &RangeSet<T>)
Subtracts
other from self.Source§impl<T: Copy + Ord> Disjoint<Range<T>> for RangeSet<T>
impl<T: Copy + Ord> Disjoint<Range<T>> for RangeSet<T>
Source§fn is_disjoint(&self, other: &Range<T>) -> bool
fn is_disjoint(&self, other: &Range<T>) -> bool
Returns
true if the range is disjoint with other.Source§impl<T: Copy + Ord> Disjoint<RangeSet<T>> for Range<T>
impl<T: Copy + Ord> Disjoint<RangeSet<T>> for Range<T>
Source§fn is_disjoint(&self, other: &RangeSet<T>) -> bool
fn is_disjoint(&self, other: &RangeSet<T>) -> bool
Returns
true if the range is disjoint with other.Source§impl<T: Copy + Ord> Disjoint<RangeSet<T>> for RangeSet<T>
impl<T: Copy + Ord> Disjoint<RangeSet<T>> for RangeSet<T>
Source§fn is_disjoint(&self, other: &RangeSet<T>) -> bool
fn is_disjoint(&self, other: &RangeSet<T>) -> bool
Returns
true if the range is disjoint with other.Source§impl<T: Copy + Ord> SubAssign<&Range<T>> for RangeSet<T>
impl<T: Copy + Ord> SubAssign<&Range<T>> for RangeSet<T>
Source§fn sub_assign(&mut self, rhs: &Range<T>)
fn sub_assign(&mut self, rhs: &Range<T>)
Performs the
-= operation. Read moreSource§impl<T: Copy + Ord> SubAssign<&RangeSet<T>> for RangeSet<T>
impl<T: Copy + Ord> SubAssign<&RangeSet<T>> for RangeSet<T>
Source§fn sub_assign(&mut self, rhs: &RangeSet<T>)
fn sub_assign(&mut self, rhs: &RangeSet<T>)
Performs the
-= operation. Read moreSource§impl<T: Copy + Ord> SubAssign<Range<T>> for RangeSet<T>
impl<T: Copy + Ord> SubAssign<Range<T>> for RangeSet<T>
Source§fn sub_assign(&mut self, rhs: Range<T>)
fn sub_assign(&mut self, rhs: Range<T>)
Performs the
-= operation. Read moreSource§impl<T: Copy + Ord> SubAssign for RangeSet<T>
impl<T: Copy + Ord> SubAssign for RangeSet<T>
Source§fn sub_assign(&mut self, rhs: RangeSet<T>)
fn sub_assign(&mut self, rhs: RangeSet<T>)
Performs the
-= operation. Read moreSource§impl<T: Copy + Ord> SymmetricDifferenceMut<Range<T>> for RangeSet<T>
impl<T: Copy + Ord> SymmetricDifferenceMut<Range<T>> for RangeSet<T>
Source§fn symmetric_difference_mut(&mut self, other: &Range<T>)
fn symmetric_difference_mut(&mut self, other: &Range<T>)
Replaces
self with the set symmetric difference of self and other.Source§impl<T: Copy + Ord> SymmetricDifferenceMut<RangeSet<T>> for RangeSet<T>
impl<T: Copy + Ord> SymmetricDifferenceMut<RangeSet<T>> for RangeSet<T>
Source§fn symmetric_difference_mut(&mut self, other: &RangeSet<T>)
fn symmetric_difference_mut(&mut self, other: &RangeSet<T>)
Replaces
self with the set symmetric difference of self and other.Source§impl<T: Copy + Ord> ToRangeSet<T> for RangeSet<T>
impl<T: Copy + Ord> ToRangeSet<T> for RangeSet<T>
Source§fn to_range_set(&self) -> RangeSet<T>
fn to_range_set(&self) -> RangeSet<T>
Returns a corresponding range set.
impl<T: Eq> Eq for RangeSet<T>
impl<T> StructuralPartialEq for RangeSet<T>
Auto Trait Implementations§
impl<T> Freeze for RangeSet<T>
impl<T> RefUnwindSafe for RangeSet<T>where
T: RefUnwindSafe,
impl<T> Send for RangeSet<T>where
T: Send,
impl<T> Sync for RangeSet<T>where
T: Sync,
impl<T> Unpin for RangeSet<T>where
T: Unpin,
impl<T> UnwindSafe for RangeSet<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more