MCPcopy Create free account
hub / github.com/Genivia/ugrep / advance_pattern_min2

Method advance_pattern_min2

lib/matcher.cpp:1971–2027  ·  view source on GitHub ↗

Minimal 2 byte long patterns with min=2 using bitap hashed pairs then PM

Source from the content-addressed store, hash-verified

1969
1970/// Minimal 2 byte long patterns with min=2 using bitap hashed pairs then PM
1971bool Matcher::advance_pattern_min2(size_t loc)
1972{
1973 const Pattern::Bitap *tap = pat_->tap_;
1974 uint32_t state = ~0;
1975 while (true)
1976 {
1977 const char *s = buf_ + loc;
1978 const char *e = buf_ + end_ - (Pattern::Const::PM_M - 1);
1979 uint8_t c0 = static_cast<uint8_t>(*s);
1980 while (s < e)
1981 {
1982 uint8_t c1 = static_cast<uint8_t>(*++s);
1983 state = (state << 1) | tap[Pattern::bihash(c0, c1)];
1984 c0 = c1;
1985 if ((state & 2) == 0 && pat_->predict_match(s - 2))
1986 {
1987 size_t k = s - buf_ - 2;
1988 set_current(k);
1989 return true;
1990 }
1991 }
1992 loc = s - buf_;
1993 size_t m = std::min<size_t>(1, loc); // to clamp loc - 1
1994 set_current_and_peek_more(loc - m); // clamp loc - 1
1995 loc = cur_ + m;
1996 if (loc + (Pattern::Const::PM_M - 1) >= end_ && eof_)
1997 {
1998 // keep going, we may have matches in the last bytes
1999 s = buf_ + loc;
2000 e = buf_ + end_ - 1;
2001 c0 = static_cast<uint8_t>(s[0]);
2002 while (s < e)
2003 {
2004 uint8_t c1 = static_cast<uint8_t>(*++s);
2005 state = (state << 1) | tap[Pattern::bihash(c0, c1)];
2006 c0 = c1;
2007 if ((state & 2) == 0)
2008 {
2009 size_t k = s - buf_ - 2;
2010 set_current(k);
2011 return true;
2012 }
2013 }
2014 uint8_t c1 = 0; // reached the end
2015 state = (state << 1) | tap[Pattern::bihash(c0, c1)];
2016 if ((state & 2) == 0)
2017 {
2018 size_t k = s - buf_ - 1;
2019 set_current(k);
2020 return true;
2021 }
2022 loc = s - buf_;
2023 set_current(loc);
2024 return false;
2025 }
2026 }
2027}
2028

Callers

nothing calls this directly

Calls 1

predict_matchMethod · 0.80

Tested by

no test coverage detected