pub struct SegmentedPriorityQueue<T> { /* private fields */ }Expand description
Like a [PriorityQueue] but avoids starvation by
using a rotating bip-buffer of priority queues.
Implementations§
Source§impl<T> SegmentedPriorityQueue<T>
impl<T> SegmentedPriorityQueue<T>
pub fn new() -> SegmentedPriorityQueue<T>
Sourcepub fn push(&self, t: T, priority: u64)
pub fn push(&self, t: T, priority: u64)
Higher priority tends to gets popped first.
The internal bip buffer of priority queues gets rotated when the read side is empty.
§Examples
let pq = komora_sync::SegmentedPriorityQueue::new();
pq.push(2, 2);
pq.push(1, 1);
// internal state:
// read buffer: []
// write buffer: [2, 1]
// queue rotated on pop when read buffer is empty
assert_eq!(pq.pop(), 2);
// internal state:
// read buffer: [1]
// write buffer: []
// new writes get pushed to write buffer
pq.push(4, 4);
pq.push(3, 3);
// internal state:
// read buffer: [1]
// write buffer: [4, 3]
// this is the last element in the reader side
assert_eq!(pq.pop(), 1);
// queue rotated on pop when reader is empty
assert_eq!(pq.pop(), 4);
assert_eq!(pq.pop(), 3);pub fn pop(&self) -> T
Trait Implementations§
Source§impl<T: Debug> Debug for SegmentedPriorityQueue<T>
impl<T: Debug> Debug for SegmentedPriorityQueue<T>
Auto Trait Implementations§
impl<T> !Freeze for SegmentedPriorityQueue<T>
impl<T> RefUnwindSafe for SegmentedPriorityQueue<T>
impl<T> Send for SegmentedPriorityQueue<T>where
T: Send,
impl<T> Sync for SegmentedPriorityQueue<T>where
T: Send,
impl<T> Unpin for SegmentedPriorityQueue<T>where
T: Unpin,
impl<T> UnsafeUnpin for SegmentedPriorityQueue<T>
impl<T> UnwindSafe for SegmentedPriorityQueue<T>
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