Methods like sort_by
on std::slice::MutableSliceAllocating
or sort_by
on collections::vec::Vec
are documented to "allocate approximately 2 * n, where n is the length". I don't think that good C++ std::sort
implementations allocate (on the heap) and yet they accomplish the same O(n log n) complexity. Although, the Rust sort methods are stable unlike the C++ std::sort.
Why do the Rust sort methods allocate? To me, it doesn't fit the "zero cost abstraction" bill advertised here.