-
Notifications
You must be signed in to change notification settings - Fork 58
API: Add Vector.sort() #105
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
Conversation
|
Looks good to me. I wonder if we can go a step further by allowing the user to specify the ordering function? Maybe an Option so we can default to the current sort? I'm not sure if this is a good idea or not. The pr as it is can be merged. |
|
I think we should think much more thoroughly about this. Rust has separate For example, consider complex numbers. Complex numbers are not a totally ordered set (with respect to their magnitude) unless you impose some additional ordering constraints. Trying to sort a vector of complex numbers may thus give unexpected results (panic at runtime). This is exactly the reason why the |
|
Ok, how about:
|
|
Sort of playing the (conservative) devil's advocate here:
Finally, sorting floating point numbers in this fashion should probably be something like a "try sort", i.e. it should rather return a |
|
I agree with most of what @Andlon has said. Although right now we do not have the means to sort the I think that being able to sort the vector in place seems like a useful operation. Though as pointed out above a somewhat complicated one in practice for us. Personally @sinhrks suggestion seems reasonable to me. Where possible allow us to use the |
|
@AtheMathmo: |
|
Ah yes! I'm not sure why I was under the impression this was not the case. Is there a particular reason why this is not enough for you @sinhrks ? |
|
Thx to the feedback. v What I currently wants are |
|
So is there an easy way to sort a Also |
This should simplify AtheMathmo/rusty-machine#159 a bit.
Even though normal
Vec.sortrequiresOrd,Vector.sortis available if value implsPartialOrd(to handle floating points).