pub struct Ranges(/* private fields */);Implementations§
Source§impl Ranges
impl Ranges
pub fn new(limit: usize) -> Self
Sourcepub fn insert_packet_number_range(
&mut self,
pn_range: PacketNumberRange,
) -> Result<(), Error>
pub fn insert_packet_number_range( &mut self, pn_range: PacketNumberRange, ) -> Result<(), Error>
Inserts a packet number; dropping smaller values if needed
Sourcepub fn insert_packet_number(
&mut self,
packet_number: PacketNumber,
) -> Result<(), Error>
pub fn insert_packet_number( &mut self, packet_number: PacketNumber, ) -> Result<(), Error>
Inserts a packet number; dropping smaller values if needed
Methods from Deref<Target = IntervalSet<PacketNumber>>§
Sourcepub fn set_limit(&mut self, limit: NonZeroUsize)
pub fn set_limit(&mut self, limit: NonZeroUsize)
Sets an element limit for the given IntervalSet.
The number of elements in the set cannot exceed this
amount, otherwise insert calls will be rejected
Note: calling this will not drop existing intervals
that exceed the new limit and will only be
applied to later calls to insert.
§Examples
use core::num::NonZeroUsize;
let mut set = IntervalSet::new();
assert!(set.insert(0..4).is_ok());
set.set_limit(NonZeroUsize::new(1).unwrap());
assert!(set.insert(4..8).is_ok());
assert!(set.insert(12..16).is_err());Sourcepub fn remove_limit(&mut self)
pub fn remove_limit(&mut self)
Removes the element limit for the given IntervalSet.
§Examples
use core::num::NonZeroUsize;
let mut set = IntervalSet::with_limit(NonZeroUsize::new(1).unwrap());
assert!(set.insert(0..4).is_ok());
assert!(set.insert(4..8).is_ok());
assert!(set.insert(12..16).is_err());
set.remove_limit();
assert!(set.insert(12..16).is_ok());Sourcepub fn interval_len(&self) -> usize
pub fn interval_len(&self) -> usize
Sourcepub fn insert<R: RangeBounds<T>>(
&mut self,
interval: R,
) -> Result<(), IntervalSetError>
pub fn insert<R: RangeBounds<T>>( &mut self, interval: R, ) -> Result<(), IntervalSetError>
Sourcepub fn insert_front<R: RangeBounds<T>>(
&mut self,
interval: R,
) -> Result<(), IntervalSetError>
pub fn insert_front<R: RangeBounds<T>>( &mut self, interval: R, ) -> Result<(), IntervalSetError>
Inserts the supplied interval at the beginning of the IntervalSet.
This method can be used to optimize insertion when the interval is less
than all of the current intervals.
§Examples
let mut set = IntervalSet::new();
assert!(set.insert_front(0..4).is_ok());
assert!(set.contains(&3));
assert!(!set.contains(&5));Sourcepub fn insert_value(&mut self, value: T) -> Result<(), IntervalSetError>
pub fn insert_value(&mut self, value: T) -> Result<(), IntervalSetError>
Sourcepub fn union(&mut self, other: &Self) -> Result<(), IntervalSetError>
pub fn union(&mut self, other: &Self) -> Result<(), IntervalSetError>
Performs a union, i.e., all the values in self or other will
be present in self
§Examples
let mut a = IntervalSet::new();
assert!(a.insert(0..4).is_ok());
let mut b = IntervalSet::new();
assert!(b.insert(4..8).is_ok());
a.union(&b);
assert_eq!(a.iter().collect::<Vec<_>>(), (0..8).collect::<Vec<_>>());Sourcepub fn remove<R: RangeBounds<T>>(
&mut self,
interval: R,
) -> Result<(), IntervalSetError>
pub fn remove<R: RangeBounds<T>>( &mut self, interval: R, ) -> Result<(), IntervalSetError>
Sourcepub fn remove_value(&mut self, value: T) -> Result<(), IntervalSetError>
pub fn remove_value(&mut self, value: T) -> Result<(), IntervalSetError>
Sourcepub fn difference(&mut self, other: &Self) -> Result<(), IntervalSetError>
pub fn difference(&mut self, other: &Self) -> Result<(), IntervalSetError>
Performs a difference, i.e., all the values that are in self but not
in other will be present in self.
§Examples
let mut set_a = IntervalSet::new();
assert!(set_a.insert(0..=10).is_ok());
let mut set_b = IntervalSet::new();
assert!(set_b.insert(4..=8).is_ok());
assert!(set_a.difference(&set_b).is_ok());
assert_eq!(set_a.iter().collect::<Vec<_>>(), vec![0, 1, 2, 3, 9, 10]);Sourcepub fn intersection(&mut self, other: &Self) -> Result<(), IntervalSetError>
pub fn intersection(&mut self, other: &Self) -> Result<(), IntervalSetError>
Performs an intersection, i.e., all the values in both self and other will
be present in self.
§Examples
let mut set_a = IntervalSet::new();
assert!(set_a.insert(0..=10).is_ok());
let mut set_b = IntervalSet::new();
assert!(set_b.insert(4..=8).is_ok());
assert!(set_a.intersection(&set_b).is_ok());
assert_eq!(set_a.iter().collect::<Vec<_>>(), vec![4, 5, 6, 7, 8]);Sourcepub fn intersection_iter<'a>(&'a self, other: &'a Self) -> Intersection<'a, T> ⓘ
pub fn intersection_iter<'a>(&'a self, other: &'a Self) -> Intersection<'a, T> ⓘ
Returns an iterator of Intervals over the intersection, i.e., all
the values in both self and other will be returned.
§Examples
let mut set_a = IntervalSet::new();
assert!(set_a.insert(0..=10).is_ok());
let mut set_b = IntervalSet::new();
assert!(set_b.insert(4..=8).is_ok());
let intersection = set_a.intersection_iter(&set_b).flatten();
assert_eq!(intersection.collect::<Vec<_>>(), vec![4, 5, 6, 7, 8]);