1use std::cmp::Reverse;
2
3use fpq::PriorityQueue;
4
5fn main() {
6 let score_fn = Box::new(|s: &String| s.len());
8 let mut queue = PriorityQueue::new(score_fn);
10
11 assert!(queue.peek().is_none());
13
14 queue.push("a".to_string()); queue.push("ccc".to_string()); queue.push("bb".to_string()); queue.push_with_score("b".to_string(), 10); assert_eq!(queue.peek(), Some((10, &"b".to_string())));
25
26 assert_eq!(queue.pop(), Some((10, "b".to_string())));
28 assert_eq!(queue.pop(), Some((3, "ccc".to_string())));
29 assert_eq!(queue.pop(), Some((2, "bb".to_string())));
30 assert_eq!(queue.pop(), Some((1, "a".to_string())));
31
32 assert!(queue.peek().is_none());
34
35 let score_fn = Box::new(|s: &String| Reverse(s.len()));
37 let mut queue = PriorityQueue::new(score_fn);
38
39 queue.push("a".to_string()); queue.push("ccc".to_string()); queue.push("bb".to_string()); queue.push_with_score("b".to_string(), Reverse(10)); assert_eq!(queue.peek(), Some((Reverse(1), &"a".to_string())));
47 assert_eq!(queue.pop(), Some((Reverse(1), "a".to_string())));
48 assert_eq!(queue.pop(), Some((Reverse(2), "bb".to_string())));
49 assert_eq!(queue.pop(), Some((Reverse(3), "ccc".to_string())));
50 assert_eq!(queue.pop(), Some((Reverse(10), "b".to_string())));
51
52 assert!(queue.peek().is_none());
53}