i was playing with something else in rust and on a...
# development
i was playing with something else in rust and on a whim decided to:
Copy code
#[derive(PartialOrd, Ord)]
struct TotallyOrderedCollectionStruct(Vec<TotallyOrderedInnerStruct>);
and was gleeful that this worked automatically, then realized it would have to have been implemented by comparing each element in the pair of vecs being compared, which is linear time per comparison. this makes sense, and i don't believe there is a better way for general vectors, but it would be nice if there was a
trait or something similar to
to differentiate ~constant-time vs linear-time comparisons (for
as well). this is definitely you-pay-for-what-you-use, but also a bit of a perf footgun that would actually affect real code unless they've tossed more SIMD at it than i can imagine, and feels a little too much like c++ in that way to me. only as a statement about things that would concern me in my own code -- it's easy enough to just remember that
can sometimes be expensive, but it would be nice to be able to toss that on there without thinking too hard (especially because if you make your code use the default
implementation, then realize this footgun after the fact, you're actually in a bit of a mess to get out from as you generally have to rethink whether you can even order the things you want performantly at all -- luckily this was not the case here as i was already thinking about sorting)