-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
proposal: slices: functions Shift, Rotate. #69808
Comments
Related Issues and Documentation (Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
Duplicate of #64103 |
The |
Ah, sorry, though I struggle to see how useful this definition of Shift is in common code? |
I agree, I'm not sure I understand where these would be useful. |
Regarding usefulness in "common code", here's what I would comment:
(notice that If that doesn't make the cut, that's understandable of course. Maybe it needs more evidence of usefulness. |
Why limit func InsertN[Slice ~[]E, E any](s Slice, i, n int, v E) Slice instead? |
I don't think there's a need, evidenced by the fact that |
Not commenting on the rest of the proposals, but |
@earthboundkid Thanks, I've added a remark in the proposal regarding the name. |
Proposal Details
Judging from the source code of the
slices
package there already is an internal "rotateLeft/Right" function. I am unsure if there is a good reason not to export this useful function (especially as it is not trivial to implement without allocations).A "Shift" function is not trivial to implement efficiently either, I think (without intermediate allocations, ie. making an zero slice of length and inserting it) . Maybe this can be done using other functions in the package that I am unaware of. In that case just an example would be nice.
(Looking at the implementation of
Insert
I think a Shift function could simplify its implementation a little. AlsoInsert
checks for overlap but this seems covered bycopy
already? Although maybe there's more to it then I can see by glancing at it).Updates after feedback
Apparently
shift
is commonly used to refer to a different operation on arrays/slices (especially in scripting languages) and bits. Alternative names forShift
such asInsertN
orInsertZeros
should be considered.The text was updated successfully, but these errors were encountered: