* as Boyer-Moore. On the upside, it does not do any upfront
* preprocessing and does not allocate memory.
*/
-template <class T>
+template <class T, class Comp = std::equal_to<typename Range<T>::value_type>>
inline size_t qfind(const Range<T> & haystack,
- const Range<T> & needle);
+ const Range<T> & needle,
+ Comp eq = Comp());
/**
* Finds the first occurrence of needle in haystack. The result is the
/**
* Finds substrings faster than brute force by borrowing from Boyer-Moore
*/
-template <class T, class Comp>
+template <class T, class Comp = std::equal_to<typename Range<T>::value_type>>
size_t qfind(const Range<T>& haystack,
const Range<T>& needle,
- Comp eq) {
+ Comp eq = Comp()) {
// Don't use std::search, use a Boyer-Moore-like trick by comparing
// the last characters first
auto const nsize = needle.size();
extern const AsciiCaseSensitive asciiCaseSensitive;
extern const AsciiCaseInsensitive asciiCaseInsensitive;
-template <class T>
-size_t qfind(const Range<T>& haystack,
- const Range<T>& needle) {
- return qfind(haystack, needle, asciiCaseSensitive);
-}
-
template <class T>
size_t qfind(const Range<T>& haystack,
const typename Range<T>::value_type& needle) {
EXPECT_THROW(a.subpiece(6), std::out_of_range);
}
+TEST(qfind, UInt32_Ranges) {
+ vector<uint32_t> a({1, 2, 3, 260, 5});
+ vector<uint32_t> b({2, 3, 4});
+
+ auto a_range = folly::Range<const uint32_t*>(&a[0], a.size());
+ auto b_range = folly::Range<const uint32_t*>(&b[0], b.size());
+
+ EXPECT_EQ(qfind(a_range, b_range), string::npos);
+
+ a[3] = 4;
+ EXPECT_EQ(qfind(a_range, b_range), 1);
+}
+
template <typename NeedleFinder>
class NeedleFinderTest : public ::testing::Test {
public: