-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking Issue for alloc::collections::BinaryHeap::as_slice
#83659
Comments
std::collections::BinaryHeap::as_slice
alloc::collections::BinaryHeap::as_slice
… r=Amanieu alloc: Added `as_slice` method to `BinaryHeap` collection I initially asked about whether it is useful addition on https://internals.rust-lang.org/t/should-i-add-as-slice-method-to-binaryheap/13816, and it seems there were no objections, so went ahead with this PR. > There is [`BinaryHeap::into_vec`](https://doc.rust-lang.org/std/collections/struct.BinaryHeap.html#method.into_vec), but it consumes the value. I wonder if there is API design limitation that should be taken into account. Implementation-wise, the inner buffer is just a Vec, so it is trivial to expose as_slice from it. Please, guide me through if I need to add tests or something else. UPD: Tracking issue rust-lang#83659
If this is added, it means that the order of the underlying slice is added to the API, which is useful for some purposes. In that case, is it possible to add a .sort_slice() method that just calls .sort() on the underlying Vec, for when you want that slice to be sorted? This does mean that the implementation details as a binary heap leaks a bit, but there are cases where you do want to alternate between having a sorted array and just having a binary heap. |
This seems useful for efficiently selecting a uniform random element. |
Can we stabilize it? |
@SmnTin would you be able to share a link or an explanation of a real-world use case? @dspyz-matician is this a real use case? In what scenario would you be keeping elements in a |
@dtolnay I have a RRT-like stochastic anytime search algorithm that continually keeps the top N strategies it's found. It randomly selects one of these strategies, clones it, performs a random modification to get a new strategy, then if the new strategy is better than the current worst, it inserts it and pops the current worst one off the top. |
Thanks! @rust-lang/libs-api:
|
Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
…rntSushi Stabilize `binary_heap_as_slice` This PR stabilizes `binary_heap_as_slice`: ```rust // std::collections::BinaryHeap impl BinaryHeap<T> { pub fn as_slice(&self) -> &[T] } ``` <br> Tracking issue: rust-lang#83659. Implementation PR: rust-lang#82331. FCPs already completed in the tracking issue. Closes rust-lang#83659. r? libs-api
…rntSushi Stabilize `binary_heap_as_slice` This PR stabilizes `binary_heap_as_slice`: ```rust // std::collections::BinaryHeap impl BinaryHeap<T> { pub fn as_slice(&self) -> &[T] } ``` <br> Tracking issue: rust-lang#83659. Implementation PR: rust-lang#82331. FCPs already completed in the tracking issue. Closes rust-lang#83659. r? libs-api
Rollup merge of rust-lang#124012 - slanterns:as_slice_stabilize, r=BurntSushi Stabilize `binary_heap_as_slice` This PR stabilizes `binary_heap_as_slice`: ```rust // std::collections::BinaryHeap impl BinaryHeap<T> { pub fn as_slice(&self) -> &[T] } ``` <br> Tracking issue: rust-lang#83659. Implementation PR: rust-lang#82331. FCPs already completed in the tracking issue. Closes rust-lang#83659. r? libs-api
Feature gate:
#![feature(binary_heap_as_slice)]
This is a tracking issue for
std::collections::BinaryHeap::as_slice
, a method that returns a slice of the data that is stored in the BinaryHeap (the order is arbitrary).Public API
Steps / History
as_slice
method toBinaryHeap
collection #82331Unresolved Questions
The text was updated successfully, but these errors were encountered: