(cap: usize, comparator: Comparator<T>)
| 49 | } |
| 50 | |
| 51 | fn new(cap: usize, comparator: Comparator<T>) -> Self { |
| 52 | let mut pq = Self { |
| 53 | pq: Vec::with_capacity(cap + 1), |
| 54 | n: 0, |
| 55 | comparator, |
| 56 | }; |
| 57 | |
| 58 | // 虽然此处初始化了0号元素, 但0号元素并不参与算法过程, |
| 59 | pq.pq.push(T::default()); |
| 60 | |
| 61 | pq |
| 62 | } |
| 63 | |
| 64 | /// Returns true if this priority queue is empty |
| 65 | pub fn is_empty(&self) -> bool { |