Skip to content

Commit f07235e

Browse files
Merge #262
262: add BinaryHeap::into_vec r=japaric a=Lambda-Logan std::collections::BinaryHeap provides an into_vec method https://doc.rust-lang.org/std/collections/struct.BinaryHeap.html#method.into_vec My use case is I want a sorted iterator similar to BinaryHeap.into_sorted_iter. I found my self creating a new heapless:Vec from heapless::BinaryHeap::into_iter and then sorting it. It seemed better to return the underlying vec and sort that. But the functionality seemed generally useful and helps the API jive a little better with std::collections::BinaryHeap. Do you see any issues with this implementation? Also, apologies for anything weird... This is my first PR :) Co-authored-by: Logan Dimond <[email protected]> Co-authored-by: Logan Dimond <[email protected]>
2 parents 4431ae1 + 472a839 commit f07235e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/binary_heap.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ where
336336
self.sift_up(0, old_len);
337337
}
338338

339+
/// Returns the underlying ```Vec<T,N>```. Order is arbitrary and time is O(1).
340+
pub fn into_vec(self) -> Vec<T, N> {
341+
self.data
342+
}
343+
339344
/* Private API */
340345
fn sift_down_to_bottom(&mut self, mut pos: usize) {
341346
let end = self.len();

0 commit comments

Comments
 (0)