PQueue

Struct PQueue 

Source
pub struct PQueue<T>
where T: Eq + Hash + Clone,
{ /* 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>
where T: Eq + Hash + Clone,

Source

pub fn new() -> Self

Creates a new empty priority queue with thread-safe Arc<Mutex<T>> wrapper.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn stats(&self) -> PQueueStats

Get the statistics of the priority queue.

Returns the statistics of the priority queue.

Trait Implementations§

Source§

impl<T> Clone for PQueue<T>
where T: Eq + Hash + Clone,

Source§

fn clone(&self) -> Self

Creates a shallow clone that shares the same internal queue. Multiple cloned instances will operate on the same underlying data.

1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Default for PQueue<T>
where T: Eq + Hash + Clone,

Source§

fn default() -> Self

Creates a new empty priority queue using default initialization.

Auto Trait Implementations§

§

impl<T> Freeze for PQueue<T>

§

impl<T> RefUnwindSafe for PQueue<T>

§

impl<T> Send for PQueue<T>
where T: Sync + Send,

§

impl<T> Sync for PQueue<T>
where T: Sync + Send,

§

impl<T> Unpin for PQueue<T>

§

impl<T> UnwindSafe for PQueue<T>

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.