Skip to content

Add FindLast and FindLastIf to contrib/algo - #3540

Merged
copybara-service[bot] merged 2 commits into
google:masterfrom
fallintoplace:add-find-last-algo
Nov 11, 2026
Merged

copybara-service[bot] merged 2 commits into
google:masterfrom
fallintoplace:add-find-last-algo

Conversation

@fallintoplace

Copy link
Copy Markdown
Contributor

What

  • Add FindLast and FindLastIf.

Why

  • Find the last matching element in a range.

Implementation

  • Scan from the end and mask the final partial block.

@jan-wassenberg jan-wassenberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding :) One minor suggestion:

Comment thread hwy/contrib/algo/find-inl.h Outdated
// `count` if not found.
template <class D, typename T = TFromD<D>>
size_t FindLast(D d, T value, const T* HWY_RESTRICT in, size_t count) {
return FindLastIf(d, in, count, detail::FindEqualTo<T>{value});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more typical to have a lambda here - let's remember to add HWY_ATTR before the opening { .
We can then remove FindEqualTo.

@jan-wassenberg jan-wassenberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@copybara-service
copybara-service Bot merged commit 886c883 into google:master Nov 11, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants