FlatQueue

Struct FlatQueue 

Source
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>

Source

pub fn new() -> Self

Creates a new empty queue.

Source

pub fn len(&self) -> usize

Returns the number of items.

Source

pub fn is_empty(&self) -> bool

Returns whether the queue is empty.

Source

pub fn clear(&mut self)

Clears all items from the queue.

Source

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 add
  • priority: the priority of the item
Source

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

Source

pub fn peek(&self) -> Option<&T>

Returns the item with the lowest priority without removing it.

Source

pub fn peek_value(&self) -> Option<f64>

Returns the priority of the lowest-priority item.

Source

pub fn shrink(&mut self)

Shrinks underlying arrays to current length.

Trait Implementations§

Source§

impl<T: Clone> Default for FlatQueue<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

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().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V