//! A priority queue implemented with a binary heap.
//!
+//! Insertions have `O(log n)` time complexity and checking or popping the largest element is
+//! `O(1)`. Converting a vector to a priority queue can be done in-place, and has `O(n)`
+//! complexity. A priority queue can also be converted to a sorted vector in-place, allowing it to
+//! be used for an `O(n log n)` in-place heapsort.
+//!
//! # Example
//!
//! This is a larger example which implements [Dijkstra's algorithm][dijkstra]
}
/// `PriorityQueue` iterator.
-pub struct Items <'a, T> {
+pub struct Items <'a, T:'a> {
iter: slice::Items<'a, T>,
}
}
impl<T: Ord> FromIterator<T> for PriorityQueue<T> {
- fn from_iter<Iter: Iterator<T>>(iter: Iter) -> PriorityQueue<T> {
- let mut q = PriorityQueue::new();
- q.extend(iter);
- q
+ fn from_iter<Iter: Iterator<T>>(mut iter: Iter) -> PriorityQueue<T> {
+ let vec: Vec<T> = iter.collect();
+ PriorityQueue::from_vec(vec)
}
}