Skip to content
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

Maybe add mp_set_find #89

Open
rolandschulz opened this issue Jan 7, 2024 · 3 comments
Open

Maybe add mp_set_find #89

rolandschulz opened this issue Jan 7, 2024 · 3 comments

Comments

@rolandschulz
Copy link

In cases a list is a set it is possible to do mp_find quicker. Is it worth to add this?

template <class S>
using mp_enumerate = mp_transform<mp_list, S, mp_iota<mp_size<S>>>;
template <class S, class V>
using mp_set_find = mp_second<mp_map_find<mp_enumerate<S>, V>>;
@pdimov
Copy link
Member

pdimov commented Jan 7, 2024

Probably makes sense for completeness. I wonder what's the actual difference in performance in 2024 compared to mp_find, though.

@rolandschulz
Copy link
Author

The speedup isn't huge with modern gcc/clang. With icx 2024.1 I get for

using S = mp_iota_c<100>;

template <class S>
using mp_enumerate = mp_transform<mp_list, S, mp_iota<mp_size<S>>>;

using E = mp_enumerate<S>;

template <class S, class V>
using mp_set_find = mp_second<mp_map_find<E, V>>;
// using mp_set_find = mp_find<S,V>;

template<class A, class B> using F = mp_less<mp_set_find<S, A>, mp_set_find<S, B>>;
static_assert(std::is_same_v<mp_sort<S, F>, S>);

1.6s for mp_set_find and 2.2s for mp_find.

@pdimov
Copy link
Member

pdimov commented Jan 8, 2024

I think this is an improvement that justifies having mp_set_find.

I'd like to add mp_enumerate as well, but most other languages (and std::views::enumerate) put the index first, not second. (Which is actually what mp_at uses.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants