pub struct PriorityQueue<F, T>where
    F: Fn(&T, &T) -> bool,
    T: PartialOrd + Debug,
{ /* private fields */ }
Expand description

PriorityQueue

This data structure implements a Priority Queue with a comparator function to specify the Min/Max heap. The queue is implemented as a heap of indexes.

Implementations§

Create a new PriorityQueue with a comparator function

Example
use flex_algo::priority_queue::PriorityQueue;
 
let mut pq = PriorityQueue::new(|a: &usize,b: &usize| a < b);
 

Return the size of the PriorityQueue

Example
use flex_algo::priority_queue::PriorityQueue;
 
let mut pq = PriorityQueue::new(|a: &usize,b: &usize| a < b);
assert_eq!(pq.size(), 0);

Return true if the PriorityQueue is empty

Example
use flex_algo::priority_queue::PriorityQueue;
 
let mut pq = PriorityQueue::new(|a: &usize,b: &usize| a < b);
assert_eq!(pq.is_empty(), true);

Push element into Priority Queue and return the size of the PriorityQueue

Example
use flex_algo::priority_queue::PriorityQueue;
 
let mut pq = PriorityQueue::new(|a: &usize,b: &usize| a < b);
pq.push(14);
pq.push(10);
let len = pq.push(12);
 
assert_eq!(len, 3);

Return the first element of the heap, or None if it is empty.

Example
use flex_algo::priority_queue::PriorityQueue;
 
let mut pq = PriorityQueue::new(|a: &usize,b: &usize| a < b);
pq.push(14);
pq.push(10);
pq.push(12);
 
assert_eq!(pq.pop().unwrap(), 10);

Return the first element of the heap, or None if it is empty without change the heap.

Example
use flex_algo::priority_queue::PriorityQueue;
 
let mut pq = PriorityQueue::new(|a: &usize,b: &usize| a < b);
pq.push(14);
pq.push(10);
pq.push(12);
 
assert_eq!(pq.peek().unwrap(), &10);

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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