pub struct FlatQueue<T> { /* private fields */ }Expand description
§FlatQueue
§Description
A priority queue implemented using a binary heap.
A port from the flatqueue code.
§Usage
use gistools::data_structures::FlatQueue;
let mut q = FlatQueue::new();
q.push(1, 1.0);
q.push(3, 3.0);
q.push(2, 2.0);
assert_eq!(q.pop(), Some(1));
assert_eq!(q.pop(), Some(2));
assert_eq!(q.pop(), Some(3));
assert_eq!(q.pop(), None);Implementations§
Source§impl<T: Clone> FlatQueue<T>
impl<T: Clone> FlatQueue<T>
Sourcepub fn push(&mut self, item: T, priority: f64)
pub fn push(&mut self, item: T, priority: f64)
Adds item to the queue with the specified priority.
priority must be a number. Items are sorted and returned from low to high priority. Multiple items
with the same priority value can be added to the queue, but there is no guaranteed order between these items.
§Parameters
item: the item to addpriority: the priority of the item
Sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Removes and returns the item from the head of this queue, which is one of
the items with the lowest priority. If this queue is empty, returns undefined.
§Returns
the item from the head of this queue
Sourcepub fn peek(&self) -> Option<&T>
pub fn peek(&self) -> Option<&T>
Returns the item with the lowest priority without removing it.
Sourcepub fn peek_value(&self) -> Option<f64>
pub fn peek_value(&self) -> Option<f64>
Returns the priority of the lowest-priority item.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for FlatQueue<T>
impl<T> RefUnwindSafe for FlatQueue<T>where
T: RefUnwindSafe,
impl<T> Send for FlatQueue<T>where
T: Send,
impl<T> Sync for FlatQueue<T>where
T: Sync,
impl<T> Unpin for FlatQueue<T>where
T: Unpin,
impl<T> UnwindSafe for FlatQueue<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().