#include <eve/module/algo/algo/search.hpp>
Defined in Header
#include <eve/module/algo.hpp>
Some ideas are taken from the previous work:
- Note
- : to look for one element use
eve::algo::find. It is also slightly faster, so if one element case is common - you might consider an if on the needle len.
Tuning:
- Aligning search for initial test. Passing
no_aligning will remove this aligning.
- Unrolling search for initial test. By default we unroll 4 times, with expensive predicates might not be benificial
namespace eve::algo
{
template<relaxed_range R1, relaxed_range R2, typename Equal>
template<relaxed_range R1, relaxed_range R2>
}
constexpr auto search
SIMD version of std::search (subsequence in a sequence).
Definition search.hpp:426
typename decltype(detail::as_translated_type(as< T >{}))::type translate_t
Returns the final translated type of T.
Definition translation.hpp:107
(2) calls (1) with eve::is_equal. In order to mimic the behaviour of std::search, it will also cast the types, so that you can search unrelated types.
Version (1) won't do implicit types conversions for you, you can either handle them in the predicate or use views::convert.
Parameters (1)
- haystack - where we search the subsequence.
- needle - the subsequence we are searching for.
- equal - the predicate of the elements.
Return value
unaligned iterator pointing to where in haystack the sequence is.
If the needle is empty found == haystack.begin() is returned.
If the needle isn't found == haystack.end().
#include <eve/module/algo.hpp>
#include <eve/module/core.hpp>
#include <span>
#include <vector>
#include <string_view>
#include <iostream>
std::ptrdiff_t
{
std::span
h(
reinterpret_cast<const std::uint8_t *
>(
haystack.data()),
haystack.size());
std::span
n(
reinterpret_cast<const std::uint8_t *
>(
needle.data()),
needle.size());
}
void
{
std::string_view
haystack(
"one two three");
std::cout << "<<<<<<<\n" << std::endl;
}
void
{
std::cout <<
"<<< " <<
__func__ <<
" <<<" << std::endl;
std::vector<double>
haystack {0.0, 1.0, 2.0, 3.0, 4.0, 5.0};
std::vector<std::int8_t>
needle {2, 3};
<< std::endl;
std::cout << "<<<<<<<\n" << std::endl;
}
std::ptrdiff_t
{
std::span
h(
reinterpret_cast<const std::uint8_t *
>(
haystack.data()),
haystack.size());
std::span
n(
reinterpret_cast<const std::uint8_t *
>(
needle.data()),
needle.size());
{
};
}
void
{
std::cout <<
"<<< " <<
__func__ <<
" <<<" << std::endl;
std::cout << "substring_in_string_case_insensitive: "
std::cout << "substring_in_string_case_insensitive: "
std::cout << "<<<<<<<\n" << std::endl;
}
int
{
}
Specifies semantic compatibility between wrapper/wrapped types.
Definition product_type.hpp:107
constexpr auto sub
tuple_callable computing the difference of its first argument with the sum of the others.
Definition sub.hpp:109