Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb_re2::FactorAlternationImpl Class Reference

Static Public Member Functions

static void Round1 (Regexp **sub, int nsub, Regexp::ParseFlags flags, std::vector< Splice > *splices)
static void Round2 (Regexp **sub, int nsub, Regexp::ParseFlags flags, std::vector< Splice > *splices)
static void Round3 (Regexp **sub, int nsub, Regexp::ParseFlags flags, std::vector< Splice > *splices)

Member Function Documentation

◆ Round1()

void duckdb_re2::FactorAlternationImpl::Round1 ( Regexp ** sub,
int nsub,
Regexp::ParseFlags flags,
std::vector< Splice > * splices )
static
467700 {
467701 // Round 1: Factor out common literal prefixes.
467702 int start = 0;
467703 Rune* rune = NULL;
467704 int nrune = 0;
467705 Regexp::ParseFlags runeflags = Regexp::NoParseFlags;
467706 for (int i = 0; i <= nsub; i++) {
467707 // Invariant: sub[start:i] consists of regexps that all
467708 // begin with rune[0:nrune].
467709 Rune* rune_i = NULL;
467710 int nrune_i = 0;
467711 Regexp::ParseFlags runeflags_i = Regexp::NoParseFlags;
467712 if (i < nsub) {
467713 rune_i = Regexp::LeadingString(sub[i], &nrune_i, &runeflags_i);
467714 if (runeflags_i == runeflags) {
467715 int same = 0;
467716 while (same < nrune && same < nrune_i && rune[same] == rune_i[same])
467717 same++;
467718 if (same > 0) {
467719 // Matches at least one rune in current range. Keep going around.
467720 nrune = same;
467721 continue;
467722 }
467723 }
467724 }
467725
467726 // Found end of a run with common leading literal string:
467727 // sub[start:i] all begin with rune[0:nrune],
467728 // but sub[i] does not even begin with rune[0].
467729 if (i == start) {
467730 // Nothing to do - first iteration.
467731 } else if (i == start+1) {
467732 // Just one: don't bother factoring.
467733 } else {
467734 Regexp* prefix = Regexp::LiteralString(rune, nrune, runeflags);
467735 for (int j = start; j < i; j++)
467736 Regexp::RemoveLeadingString(sub[j], nrune);
467737 splices->emplace_back(prefix, sub + start, i - start);
467738 }
467739
467740 // Prepare for next iteration (if there is one).
467741 if (i < nsub) {
467742 start = i;
467743 rune = rune_i;
467744 nrune = nrune_i;
467745 runeflags = runeflags_i;
467746 }
467747 }
467748}

◆ Round2()

void duckdb_re2::FactorAlternationImpl::Round2 ( Regexp ** sub,
int nsub,
Regexp::ParseFlags flags,
std::vector< Splice > * splices )
static
467752 {
467753 // Round 2: Factor out common simple prefixes,
467754 // just the first piece of each concatenation.
467755 // This will be good enough a lot of the time.
467756 //
467757 // Complex subexpressions (e.g. involving quantifiers)
467758 // are not safe to factor because that collapses their
467759 // distinct paths through the automaton, which affects
467760 // correctness in some cases.
467761 int start = 0;
467762 Regexp* first = NULL;
467763 for (int i = 0; i <= nsub; i++) {
467764 // Invariant: sub[start:i] consists of regexps that all
467765 // begin with first.
467766 Regexp* first_i = NULL;
467767 if (i < nsub) {
467768 first_i = Regexp::LeadingRegexp(sub[i]);
467769 if (first != NULL &&
467770 // first must be an empty-width op
467771 // OR a char class, any char or any byte
467772 // OR a fixed repeat of a literal, char class, any char or any byte.
467773 (first->op() == kRegexpBeginLine ||
467774 first->op() == kRegexpEndLine ||
467775 first->op() == kRegexpWordBoundary ||
467776 first->op() == kRegexpNoWordBoundary ||
467777 first->op() == kRegexpBeginText ||
467778 first->op() == kRegexpEndText ||
467779 first->op() == kRegexpCharClass ||
467780 first->op() == kRegexpAnyChar ||
467781 first->op() == kRegexpAnyByte ||
467782 (first->op() == kRegexpRepeat &&
467783 first->min() == first->max() &&
467784 (first->sub()[0]->op() == kRegexpLiteral ||
467785 first->sub()[0]->op() == kRegexpCharClass ||
467786 first->sub()[0]->op() == kRegexpAnyChar ||
467787 first->sub()[0]->op() == kRegexpAnyByte))) &&
467788 Regexp::Equal(first, first_i))
467789 continue;
467790 }
467791
467792 // Found end of a run with common leading regexp:
467793 // sub[start:i] all begin with first,
467794 // but sub[i] does not.
467795 if (i == start) {
467796 // Nothing to do - first iteration.
467797 } else if (i == start+1) {
467798 // Just one: don't bother factoring.
467799 } else {
467800 Regexp* prefix = first->Incref();
467801 for (int j = start; j < i; j++)
467802 sub[j] = Regexp::RemoveLeadingRegexp(sub[j]);
467803 splices->emplace_back(prefix, sub + start, i - start);
467804 }
467805
467806 // Prepare for next iteration (if there is one).
467807 if (i < nsub) {
467808 start = i;
467809 first = first_i;
467810 }
467811 }
467812}

◆ Round3()

void duckdb_re2::FactorAlternationImpl::Round3 ( Regexp ** sub,
int nsub,
Regexp::ParseFlags flags,
std::vector< Splice > * splices )
static
467816 {
467817 // Round 3: Merge runs of literals and/or character classes.
467818 int start = 0;
467819 Regexp* first = NULL;
467820 for (int i = 0; i <= nsub; i++) {
467821 // Invariant: sub[start:i] consists of regexps that all
467822 // are either literals (i.e. runes) or character classes.
467823 Regexp* first_i = NULL;
467824 if (i < nsub) {
467825 first_i = sub[i];
467826 if (first != NULL &&
467827 (first->op() == kRegexpLiteral ||
467828 first->op() == kRegexpCharClass) &&
467829 (first_i->op() == kRegexpLiteral ||
467830 first_i->op() == kRegexpCharClass))
467831 continue;
467832 }
467833
467834 // Found end of a run of Literal/CharClass:
467835 // sub[start:i] all are either one or the other,
467836 // but sub[i] is not.
467837 if (i == start) {
467838 // Nothing to do - first iteration.
467839 } else if (i == start+1) {
467840 // Just one: don't bother factoring.
467841 } else {
467842 CharClassBuilder ccb;
467843 for (int j = start; j < i; j++) {
467844 Regexp* re = sub[j];
467845 if (re->op() == kRegexpCharClass) {
467846 CharClass* cc = re->cc();
467847 for (CharClass::iterator it = cc->begin(); it != cc->end(); ++it)
467848 ccb.AddRange(it->lo, it->hi);
467849 } else if (re->op() == kRegexpLiteral) {
467850 ccb.AddRangeFlags(re->rune(), re->rune(), re->parse_flags());
467851 } else {
467852 LOG(DFATAL) << "RE2: unexpected op: " << re->op() << " "
467853 << re->ToString();
467854 }
467855 re->Decref();
467856 }
467857 Regexp* re = Regexp::NewCharClass(ccb.GetCharClass(), flags);
467858 splices->emplace_back(re, sub + start, i - start);
467859 }
467860
467861 // Prepare for next iteration (if there is one).
467862 if (i < nsub) {
467863 start = i;
467864 first = first_i;
467865 }
467866 }
467867}
GMat sub(const GMat &src1, const GMat &src2, int ddepth=-1)

The documentation for this class was generated from the following file: