29 const size_t n =
std::distance(pat_first, pat_last);
30 constexpr auto uchar_max = (std::numeric_limits<uchar>::max)();
31 uchar max = n > uchar_max ? uchar_max : uchar(n);
32 q20::fill(std::begin(m_skiptable), std::end(m_skiptable), max);
34 RandomIt1 pattern =
std::next(pat_first, n - max);
36 m_skiptable[hf(*pattern++)] = max;
40 constexpr auto operator()(RandomIt2 first, RandomIt2 last, RandomIt1 pat_first,
41 RandomIt1 pat_last)
const
49 auto pat_length =
std::distance(pat_first, pat_last);
51 return R{ first, first };
53 auto haystack_length =
std::distance(first, last);
54 if (haystack_length < pat_length)
55 return R{ last, last };
57 const qsizetype pl_minus_one = qsizetype(pat_length - 1);
58 RandomIt2 current = first + pl_minus_one;
61 while (current < last - skip) {
63 skip = m_skiptable[hf(*current)];
66 while (skip < pat_length) {
67 if (!pred(hf(*(current - skip)), hf(pat_first[pl_minus_one - skip])))
71 if (skip > pl_minus_one) {
72 auto match = current + 1 - skip;
73 return R{ match, match + pat_length };
78 if (m_skiptable[hf(*(current - skip))] == pat_length)
79 skip = pat_length - skip;
85 return R{ last, last };