30 const size_t n =
std::distance(pat_first, pat_last);
31 constexpr auto uchar_max = (std::numeric_limits<uchar>::max)();
32 uchar max = n > uchar_max ? uchar_max : uchar(n);
33 q20::fill(std::begin(m_skiptable), std::end(m_skiptable), max);
35 RandomIt1 pattern =
std::next(pat_first, n - max);
37 m_skiptable[hf(*pattern++)] = max;
41 constexpr auto operator()(RandomIt2 first, RandomIt2 last, RandomIt1 pat_first,
42 RandomIt1 pat_last)
const
50 auto pat_length =
std::distance(pat_first, pat_last);
52 return R{ first, first };
54 auto haystack_length =
std::distance(first, last);
55 if (haystack_length < pat_length)
56 return R{ last, last };
58 const qsizetype pl_minus_one = qsizetype(pat_length - 1);
59 RandomIt2 current = first + pl_minus_one;
62 while (current < last - skip) {
64 skip = m_skiptable[hf(*current)];
67 while (skip < pat_length) {
68 if (!pred(hf(*(current - skip)), hf(pat_first[pl_minus_one - skip])))
72 if (skip > pl_minus_one) {
73 auto match = current + 1 - skip;
74 return R{ match, match + pat_length };
79 if (m_skiptable[hf(*(current - skip))] == pat_length)
80 skip = pat_length - skip;
86 return R{ last, last };