Crate priority_queue [] [src]

This crate provide a priority queue backed by an hashmap with some efficient methods to change the priority of an element in O(log(N)) time (worst case).

The elements(called Items, of type I) must implement [Hash] (https://doc.rust-lang.org/std/hash/trait.Hash.html) and Eq traits.

The priority P may be any type that implements [Ord] (https://doc.rust-lang.org/std/cmp/trait.Ord.html). For reverse order remember the standard wrapper [Reverse<T>] (https://doc.rust-lang.org/std/cmp/struct.Reverse.html)

#Example

extern crate priority_queue;
 
use priority_queue::PriorityQueue;
       
fn main() {
    let mut pq = PriorityQueue::new();
 
    assert!(pq.is_empty());
    pq.push("Apples", 5);
    pq.push("Bananas", 8);
    pq.push("Strawberries", 23);
 
    assert_eq!(pq.peek(), Some((&"Strawberries", &23)));
     
    pq.change_priority("Bananas", 25);
    assert_eq!(pq.peek(), Some((&"Bananas", &25)));
 
    for (item, _) in pq.into_sorted_iter() {
        println!("{}", item);
    }
}

Structs

PriorityQueue

A priority queue with efficient change function to change the priority of an element.