#collection #queue #priority #priority-queue #sorted

priority-queue-rs

Priority Queue is more specialized data structure than Queue. Like ordinary queue, priority queue has same method but with a major difference. In Priority queue items are ordered by key value so that item with the lowest value of key is at front and item with the highest value of key is at rear or vice versa. So we’re assigned priority to item based on its key value. Lower the value, higher the priority. Following are the principal methods of a Priority Queue.

24 releases

0.1.26 May 30, 2021
0.1.25 May 28, 2021
0.1.7 Apr 30, 2021

#376 in Data structures

Download history 48/week @ 2022-03-12 96/week @ 2022-03-19 2/week @ 2022-04-02 1/week @ 2022-04-09 48/week @ 2022-04-23 122/week @ 2022-04-30 145/week @ 2022-05-07 408/week @ 2022-05-14 74/week @ 2022-05-21 192/week @ 2022-05-28 145/week @ 2022-06-04 2/week @ 2022-06-18

339 downloads per month

MIT license

8KB
129 lines

priority_queue

Description

Priority Queue is more specialized data structure than Queue. Like ordinary queue, priority queue has same method but with a major difference. In Priority queue items are ordered by key value so that item with the lowest value of key is at front and item with the highest value of key is at rear or vice versa. So we're assigned priority to item based on its key value. Lower the value, higher the priority. Following are the principal methods of a Priority Queue.

How To Use

fn main() {
    let mut queue = PriorityQueue::new();
    for priority in 10..10000 {
        queue.push(priority, String::from(format!("HelloWorld{}", priority)));
    }

    if let Some(t) = queue.peek() {
        println!("peek {}", t);
    }

    for priority in 0..10 {
        let value = queue.pop();
        if let Some(t) = value {
            println!("pop {}", t);
        }
    }

    if let Some(t) = queue.peek() {
        println!("peek {}", t);
    }
}

License

This library is licensed under MIT license. See LICENSE for details.

No runtime deps