-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Add search methods for packed arrays #60855
Conversation
* count() * find() * rfind()
I like adding these methods but I think both |
<argument index="0" name="value" type="int" /> | ||
<argument index="1" name="from" type="int" default="-1" /> | ||
<description> | ||
Searches the array in reverse order. Optionally, a start search index can be passed. If negative, the start index is considered relative to the end of the array. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this is not true for the current implementation. For an array with 2 elements -5 (if considered as relative to the end of array) is out of bounds. But with the current implementation it would just search the whole array (and the same would happen for positive values out of bounds).
Yeah, I thought about those too. But this is currently how the corresponding methods in plain Do you think I should change the |
I do think these methods should be changed to behave the same across these classes. But I'd say firstly there should be consensus about what the proper/expected behavior is. If there would be such consensus then sure, I don't have anything against adding such changes in this PR. On the other hand I guess if it was made like that in the |
I created a issue for the current index handling inconsistency among array methods: #60878 Let's fix that in another PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added docs for rfind()
are still incorrect here but I guess they can be also fixed in another PR (the one making find()
/rfind()
consistent).
Thanks! |
Adds the following methods to packed arrays:
count()
find()
rfind()
They are useful because:
remove_at()
requires an index. Currently, onlybsearch()
provides an index and it requires to sort the array first.Array
already provides these methods.