You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But sometimes you want to break up your data into more than just two groups. Maybe three; or maybe the count depends on some runtime criteria.
And also, sometimes the element itself is not the relevant predicate; sometimes the index of the element is the predicate that matters. (see e.g. #15418.)
This would work by creating N vectors, where N == num_targets, and then the function g would map each (element, index) to the vector that it should be moved to. (If g ever returns a uint >= num_targets, then the method fails.)
(Another variant of this API would not provide num_targets up front; it would instead dynamically grow the set of output vectors as necessary to accommodate the values returned by g. But I think the above API would cover a lot of cases efficiently; at worst, num_targets could be made an Option<uint> to cover both use cases.)
The text was updated successfully, but these errors were encountered:
Well, no, the above API is silly since we already have move_iter. The use case of #15418 is trying to cover the scenario where we actually know the lengths of the vectors we are constructing ahead of time (to avoid quadratic behavior due to resize when repeatedly pushing elements to the output vectors), but that is not what I described in this ticket, since the sketched API does not provide any way for the client to say what the output lengths will/should be.
Closing (since what I proposed won't solve my problem).
Current
Vec
offers this method:That can be useful.
But sometimes you want to break up your data into more than just two groups. Maybe three; or maybe the count depends on some runtime criteria.
And also, sometimes the element itself is not the relevant predicate; sometimes the index of the element is the predicate that matters. (see e.g. #15418.)
Here's a quick sketch of a more general API:
This would work by creating N vectors, where N ==
num_targets
, and then the functiong
would map each (element, index) to the vector that it should be moved to. (Ifg
ever returns auint >= num_targets
, then the method fails.)(Another variant of this API would not provide
num_targets
up front; it would instead dynamically grow the set of output vectors as necessary to accommodate the values returned byg
. But I think the above API would cover a lot of cases efficiently; at worst,num_targets
could be made anOption<uint>
to cover both use cases.)The text was updated successfully, but these errors were encountered: