Maybe a heap data structure is what you’re looking for. Depending on the usecase you might have to first turn an unsorted Vec into a heap (runtime in O(n), which is still faster than fully sorting it), at that point you can both insert new elements and remove the minimum element within a time in O(log n).
Same person as @Gobbel2000@feddit.de, different instance.
- 1 Post
- 3 Comments
Joined 2 years ago
Cake day: April 3rd, 2024
You are not logged in. If you use a Fediverse account that is able to follow users, you can follow this user.
Gobbel2000@programming.devto
Rust@programming.dev•Error Handling in Rust vs. Exceptions in other languages
0·3 months agoThere is the
map_errmethod on Result which simplifies this case. But yes, anyhow is still easier if you don’t care that much about the error contents.

You would have to either mutate the original vector or clone it, yes. If you really want to iterate through an immutable Vec with only constant memory usage, then you probably can’t get around O(n^2) runtime, but maybe there is some time-memory-tradeoff where a small memory usage can get some time reduction.