kaspa_utils/
binary_heap.rs1use std::collections::BinaryHeap;
2
3pub trait BinaryHeapExtensions<T> {
4 fn into_sorted_iter(self) -> BinaryHeapIntoSortedIter<T>;
5}
6
7pub struct BinaryHeapIntoSortedIter<T> {
8 binary_heap: BinaryHeap<T>,
9}
10
11impl<T: Ord> Iterator for BinaryHeapIntoSortedIter<T> {
12 type Item = T;
13
14 fn next(&mut self) -> Option<Self::Item> {
15 self.binary_heap.pop()
16 }
17}
18
19impl<T> BinaryHeapExtensions<T> for BinaryHeap<T> {
20 fn into_sorted_iter(self) -> BinaryHeapIntoSortedIter<T> {
21 BinaryHeapIntoSortedIter { binary_heap: self }
22 }
23}