pub struct Map<V> { /* private fields */ }
Expand description

A data structure for tracking packets that are pending acknowledgement

The following assumptions are made and exploited

  • Packet numbers are monotonically generated and inserted
  • Packet numbers will mostly be removed in ranges
  • Packet numbers that are deemed lost will also be removed and retransmitted

This is implemented as a buffer ring with a moving range for the lower and upper bound of contained packet numbers. The following example illustrates how each field tracks state:

packets = [ PN(2), None, PN(0), PN(1) ]
                          ^ index = 2
start = PN(0)
end = PN(2)

Upon inserting PN(3) the state is now:

packets = [ PN(2), PN(3), PN(0), PN(1) ]
                          ^ index = 2
start = PN(0)
end = PN(3)

Upon removing PN(0) the state is now:

packets = [ PN(2), PN(3), None, PN(1) ]
                                ^ index = 3
start = PN(1)
end = PN(3)

Implementations§

source§

impl<V> Map<V>

source

pub fn insert(&mut self, packet_number: PacketNumber, value: V)

Inserts the given value

source

pub fn insert_or_update<F: FnOnce(&mut V)>( &mut self, packet_number: PacketNumber, value: V, update: F )

Inserts the given value into the map or updates the existing entry

source

pub fn get(&self, packet_number: PacketNumber) -> Option<&V>

Returns a reference to the V associated with the given packet_number

source

pub fn remove(&mut self, packet_number: PacketNumber) -> Option<V>

Removes the value associated with the given packet_number and returns the value if it was present

source

pub fn remove_range(&mut self, range: PacketNumberRange) -> RemoveIter<'_, V>

Removes a range of packets from the map and returns their value

source

pub fn get_range(&self) -> PacketNumberRange

Get the inclusive PacketNumberRange

source

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

Gets an iterator over the sent packet entries, sorted by PacketNumber

source

pub fn is_empty(&self) -> bool

Returns true if there are no entries

source

pub fn clear(&mut self)

Clears all of the packet information in the sent

Trait Implementations§

source§

impl<V: Clone> Clone for Map<V>

source§

fn clone(&self) -> Map<V>

Returns a copy 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<V: Debug> Debug for Map<V>

source§

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

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

impl<V> Default for Map<V>

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<V> Freeze for Map<V>

§

impl<V> RefUnwindSafe for Map<V>
where V: RefUnwindSafe,

§

impl<V> Send for Map<V>
where V: Send,

§

impl<V> Sync for Map<V>
where V: Sync,

§

impl<V> Unpin for Map<V>

§

impl<V> UnwindSafe for Map<V>
where V: UnwindSafe,

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> 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<T> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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