Struct Ranges

Source
pub struct Ranges(/* private fields */);

Implementations§

Source§

impl Ranges

Source

pub fn new(limit: usize) -> Self

Source

pub fn insert_packet_number_range( &mut self, pn_range: PacketNumberRange, ) -> Result<(), Error>

Inserts a packet number; dropping smaller values if needed

Source

pub fn insert_packet_number( &mut self, packet_number: PacketNumber, ) -> Result<(), Error>

Inserts a packet number; dropping smaller values if needed

Source

pub fn spread(&self) -> usize

Returns the overall range of the ack_ranges

Methods from Deref<Target = IntervalSet<PacketNumber>>§

Source

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());
Source

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());
Source

pub fn interval_len(&self) -> usize

Returns the number of intervals in IntervalSet.

§Examples
let mut set = IntervalSet::new();
assert_eq!(set.interval_len(), 0);
assert!(set.insert(0..4).is_ok());
assert_eq!(set.interval_len(), 1);
Source

pub fn capacity(&self) -> usize

Returns the allocated capacity of the IntervalSet.

§Examples
let mut set = IntervalSet::with_capacity(1);
assert_eq!(set.capacity(), 1);
assert!(set.insert(0..4).is_ok());
assert!(set.insert(6..10).is_ok());
assert!(set.capacity() > 1);
Source

pub fn clear(&mut self)

Clears all elements contained in the IntervalSet.

§Examples
let mut set = IntervalSet::new();
assert!(set.insert(0..4).is_ok());
set.clear();
assert!(set.is_empty());
Source

pub fn pop_min(&mut self) -> Option<Interval<T>>

Removes the lowest Interval in the set, if any

§Examples
let mut set = IntervalSet::new();
assert_eq!(set.pop_min(), None);
assert!(set.insert(0..4).is_ok());
assert_eq!(set.pop_min(), Some((0..4).into()));
Source

pub fn count(&self) -> usize

Returns the number of elements in IntervalSet.

§Examples
let mut set = IntervalSet::new();
assert_eq!(set.count(), 0);
assert!(set.insert(0..4).is_ok());
assert_eq!(set.count(), 4);
Source

pub fn is_empty(&self) -> bool

Returns true if the IntervalSet has no intervals.

§Examples
let mut set = IntervalSet::new();
assert!(set.is_empty());
assert!(set.insert(0..4).is_ok());
assert!(!set.is_empty());
Source

pub fn insert<R: RangeBounds<T>>( &mut self, interval: R, ) -> Result<(), IntervalSetError>

Inserts the supplied interval into the IntervalSet

§Examples
let mut set = IntervalSet::new();
assert!(set.insert(0..4).is_ok());
assert!(set.contains(&3));
assert!(!set.contains(&5));
Source

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));
Source

pub fn insert_value(&mut self, value: T) -> Result<(), IntervalSetError>

Inserts a single value into the IntervalSet

§Examples
let mut set = IntervalSet::new();
assert!(set.insert_value(1).is_ok());
assert!(set.contains(&1));
assert!(!set.contains(&0));
assert!(!set.contains(&2));
Source

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<_>>());
Source

pub fn remove<R: RangeBounds<T>>( &mut self, interval: R, ) -> Result<(), IntervalSetError>

Removes the supplied interval from the IntervalSet

§Examples
let mut set = IntervalSet::new();
assert!(set.insert(1..3).is_ok());
assert!(set.remove(0..4).is_ok());
assert!(set.is_empty());
Source

pub fn remove_value(&mut self, value: T) -> Result<(), IntervalSetError>

Removes a single value from the IntervalSet

§Examples
let mut set = IntervalSet::new();
assert!(set.insert_value(1).is_ok());
assert!(set.remove_value(1).is_ok());
assert!(!set.contains(&1));
Source

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]);
Source

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]);
Source

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]);
Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over all of the values contained in the given IntervalSet.

§Examples
let mut set = IntervalSet::new();
assert!(set.insert(0..5).is_ok());
assert!(set.insert(10..15).is_ok());
let items: Vec<_> = set.iter().collect();
assert_eq!(vec![0, 1, 2, 3, 4, 10, 11, 12, 13, 14], items);
Source

pub fn min_value(&self) -> Option<T>

Returns the smallest value in the given IntervalSet. If no items are present in the set, None is returned.

§Examples
let mut set = IntervalSet::new();
assert_eq!(set.min_value(), None);
assert!(set.insert(0..5).is_ok());
assert_eq!(set.min_value(), Some(0));
Source

pub fn max_value(&self) -> Option<T>

Returns the largest value in the given IntervalSet. If no items are present in the set, None is returned.

§Examples
let mut set = IntervalSet::new();
assert_eq!(set.max_value(), None);
assert!(set.insert(0..5).is_ok());
assert_eq!(set.max_value(), Some(4));
Source

pub fn contains(&self, value: &T) -> bool

Returns true if the set contains a value

§Examples
let mut set = IntervalSet::new();
assert_eq!(set.contains(&1), false);
assert!(set.insert(0..5).is_ok());
assert_eq!(set.contains(&1), true);
Source

pub fn intervals(&self) -> IntervalIter<'_, T>

Returns an iterator of Intervals contained in the IntervalSet

§Examples
let mut set = IntervalSet::new();
set.insert(0..=10);
assert_eq!(set.intervals().collect::<Vec<_>>(), vec![0..=10]);
Source

pub fn ranges(&self) -> RangeIter<'_, T>

Returns an iterator of Ranges contained in the IntervalSet

§Examples
let mut set = IntervalSet::new();
set.insert(0..=10);
assert_eq!(set.ranges().collect::<Vec<_>>(), vec![0..11]);
Source

pub fn inclusive_ranges(&self) -> RangeInclusiveIter<'_, T>

Returns an iterator of RangeInclusives contained in the IntervalSet

§Examples
let mut set = IntervalSet::new();
set.insert(0..=10);
assert_eq!(set.inclusive_ranges().collect::<Vec<_>>(), vec![0..=10]);

Trait Implementations§

Source§

impl<'a> AckRanges for &'a Ranges

Source§

impl Clone for Ranges

Source§

fn clone(&self) -> Ranges

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Ranges

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Ranges

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Deref for Ranges

Source§

type Target = IntervalSet<PacketNumber>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Ranges

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl Freeze for Ranges

§

impl RefUnwindSafe for Ranges

§

impl Send for Ranges

§

impl Sync for Ranges

§

impl Unpin for Ranges

§

impl UnwindSafe for Ranges

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> Upcast<T> for U
where T: UpcastFrom<U>,

Source§

fn upcast(self) -> T

Source§

impl<T, B> UpcastFrom<Counter<T, B>> for T

Source§

fn upcast_from(value: Counter<T, B>) -> T