Struct OrderedQueue

Source
pub struct OrderedQueue<Item: Clone + Debug> {
    pub queue: BTreeMap<u32, Item>,
    pub window: (u32, u32),
}
Expand description

An ordered queue is used to Index incoming packets over a channel within a reliable window time.

Usage:

use rak_rs::connection::queue::OrderedQueue;
let mut ord_qu: OrderedQueue<Vec<u8>> = OrderedQueue::new();
// Insert a packet with the id of "1"
ord_qu.insert(1, vec![0, 1]);
ord_qu.insert(5, vec![1, 0]);
ord_qu.insert(3, vec![2, 0]);

// Get the packets we still need.
let needed: Vec<u32> = ord_qu.missing();
assert_eq!(needed, vec![0, 2, 4]);

// We would in theory, request these packets, but we're going to insert them
ord_qu.insert(4, vec![2, 0, 0, 1]);
ord_qu.insert(2, vec![1, 0, 0, 2]);

// Now let's return our packets in order.
// Will return a vector of these packets in order by their "id".
let ordered: Vec<Vec<u8>> = ord_qu.flush();

Fields§

§queue: BTreeMap<u32, Item>

The current ordered queue channels Channel, (Highest Index, Ord Index, Item)

§window: (u32, u32)

The window for this queue.

Implementations§

Source§

impl<Item> OrderedQueue<Item>
where Item: Clone + Debug,

Source

pub fn new() -> Self

Source

pub fn next(&mut self) -> u32

Source

pub fn insert(&mut self, index: u32, item: Item) -> bool

Source

pub fn insert_abs(&mut self, index: u32, item: Item)

Source

pub fn missing(&self) -> Vec<u32>

Source

pub fn flush(&mut self) -> Vec<Item>

Forcefully flushes the incoming queue resetting the highest window to the lowest window.

THIS IS A PATCH FIX UNTIL I CAN FIGURE OUT WHY THE OTHER FLUSH IS BROKEN

Source

pub fn flush_old_impl(&mut self) -> Vec<Item>

Older, broken implementation, idk what is causing this to break after index 3 The logic here is supposed to be, remove all indexes until the highest most up to date index. and retain older indexes until the order is correct.

Trait Implementations§

Source§

impl<Item: Clone + Clone + Debug> Clone for OrderedQueue<Item>

Source§

fn clone(&self) -> OrderedQueue<Item>

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<Item: Debug + Clone + Debug> Debug for OrderedQueue<Item>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Item> Freeze for OrderedQueue<Item>

§

impl<Item> RefUnwindSafe for OrderedQueue<Item>
where Item: RefUnwindSafe,

§

impl<Item> Send for OrderedQueue<Item>
where Item: Send,

§

impl<Item> Sync for OrderedQueue<Item>
where Item: Sync,

§

impl<Item> Unpin for OrderedQueue<Item>

§

impl<Item> UnwindSafe for OrderedQueue<Item>
where Item: RefUnwindSafe,

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<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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V