pub struct PQueue<T>{ /* private fields */ }Expand description
Priority queue wrapper with internal synchronization using Arc and Mutex for thread safety.
You can clone this and pass it to multiple threads to share the same internal queue. Cloning will not copy the data, but instead, each cloned instance will point to the same internal queue.
Implementations§
Source§impl<T> PQueue<T>
impl<T> PQueue<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty priority queue with thread-safe Arc<Mutex<T>> wrapper.
Sourcepub fn update(&self, item: T, new_score: i64) -> (Option<i64>, i64)
pub fn update(&self, item: T, new_score: i64) -> (Option<i64>, i64)
Update the score of an item in the queue or adds it if it doesn’t yet exist.
Returns a tuple of the old score (None if the item didn’t yet exist)
and the new score.
Sourcepub fn peek(&self) -> Option<T>
pub fn peek(&self) -> Option<T>
Peek at the highest scoring item in the queue.
Returns the item with the highest score, or None if the queue is
empty.
Sourcepub fn next(&self) -> Option<T>
pub fn next(&self) -> Option<T>
Remove and return the highest scoring item from the queue.
Returns the item with the highest score, or None if the queue is
empty.
Sourcepub fn score(&self, item: &T) -> Option<i64>
pub fn score(&self, item: &T) -> Option<i64>
Get the current score of an item in the queue.
Returns the score of the item, or None if the item doesn’t exist in
the queue.
Sourcepub fn stats(&self) -> PQueueStats
pub fn stats(&self) -> PQueueStats
Get the statistics of the priority queue.
Returns the statistics of the priority queue.