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>
impl<Item> OrderedQueue<Item>
pub fn new() -> Self
pub fn next(&mut self) -> u32
pub fn insert(&mut self, index: u32, item: Item) -> bool
pub fn insert_abs(&mut self, index: u32, item: Item)
pub fn missing(&self) -> Vec<u32>
Sourcepub fn flush(&mut self) -> Vec<Item>
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
Sourcepub fn flush_old_impl(&mut self) -> Vec<Item>
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§
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> 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