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::Prefilter Class Reference
Collaboration diagram for duckdb_re2::Prefilter:

Classes

struct  LengthThenLex
class  Info

Public Types

enum  Op {
  ALL = 0 , NONE , ATOM , AND ,
  OR
}

Public Member Functions

 Prefilter (Op op)
Op op ()
const std::string & atom () const
void set_unique_id (int id)
int unique_id () const
std::vector< Prefilter * > * subs ()
void set_subs (std::vector< Prefilter * > *subs)
std::string DebugString () const

Static Public Member Functions

static Prefilter * FromRE2 (const RE2 *re2)

Private Types

using SSet = std::set<std::string, LengthThenLex>
using SSIter = SSet::iterator
using ConstSSIter = SSet::const_iterator

Private Member Functions

Prefilter * Simplify ()
 Prefilter (const Prefilter &)=delete
Prefilter & operator= (const Prefilter &)=delete

Static Private Member Functions

static Prefilter * And (Prefilter *a, Prefilter *b)
static Prefilter * Or (Prefilter *a, Prefilter *b)
static Prefilter * AndOr (Op op, Prefilter *a, Prefilter *b)
static Prefilter * FromRegexp (Regexp *a)
static Prefilter * FromString (const std::string &str)
static Prefilter * OrStrings (SSet *ss)
static Info * BuildInfo (Regexp *re)
static void SimplifyStringSet (SSet *ss)
static void CrossProduct (const SSet &a, const SSet &b, SSet *dst)

Private Attributes

Op op_
std::vector< Prefilter * > * subs_
std::string atom_
int unique_id_

Member Enumeration Documentation

◆ Op

enum duckdb_re2::Prefilter::Op
464641 {
464642 ALL = 0, // Everything matches
464643 NONE, // Nothing matches
464644 ATOM, // The string atom() must match
464645 AND, // All in subs() must match
464646 OR, // One of subs() must match
464647 };

Constructor & Destructor Documentation

◆ Prefilter()

duckdb_re2::Prefilter::Prefilter ( Op op)
explicit
469309 {
469310 op_ = op;
469311 subs_ = NULL;
469312 if (op_ == AND || op_ == OR)
469313 subs_ = new std::vector<Prefilter*>;
469314}

◆ ~Prefilter()

duckdb_re2::Prefilter::~Prefilter ( )
469317 {
469318 if (subs_) {
469319 for (size_t i = 0; i < subs_->size(); i++)
469320 delete (*subs_)[i];
469321 delete subs_;
469322 subs_ = NULL;
469323 }
469324}

Member Function Documentation

◆ op()

Op duckdb_re2::Prefilter::op ( )
inline
464652{ return op_; }

◆ atom()

const std::string & duckdb_re2::Prefilter::atom ( ) const
inline
464653{ return atom_; }

◆ set_unique_id()

void duckdb_re2::Prefilter::set_unique_id ( int id)
inline
464654{ unique_id_ = id; }

◆ unique_id()

int duckdb_re2::Prefilter::unique_id ( ) const
inline
464655{ return unique_id_; }

◆ subs()

std::vector< Prefilter * > * duckdb_re2::Prefilter::subs ( )
inline
464658 {
464659 DCHECK(op_ == AND || op_ == OR);
464660 return subs_;
464661 }

◆ set_subs()

void duckdb_re2::Prefilter::set_subs ( std::vector< Prefilter * > * subs)
inline
464665{ subs_ = subs; }

◆ FromRE2()

Prefilter * duckdb_re2::Prefilter::FromRE2 ( const RE2 * re2)
static
469965 {
469966 if (re2 == NULL)
469967 return NULL;
469968
469969 Regexp* regexp = re2->Regexp();
469970 if (regexp == NULL)
469971 return NULL;
469972
469973 return FromRegexp(regexp);
469974}

◆ DebugString()

std::string duckdb_re2::Prefilter::DebugString ( ) const
469930 {
469931 switch (op_) {
469932 default:
469933 LOG(DFATAL) << "Bad op in Prefilter::DebugString: " << op_;
469934 return StringPrintf("op%d", op_);
469935 case NONE:
469936 return "*no-matches*";
469937 case ATOM:
469938 return atom_;
469939 case ALL:
469940 return "";
469941 case AND: {
469942 std::string s = "";
469943 for (size_t i = 0; i < subs_->size(); i++) {
469944 if (i > 0)
469945 s += " ";
469946 Prefilter* sub = (*subs_)[i];
469947 s += sub ? sub->DebugString() : "<nil>";
469948 }
469949 return s;
469950 }
469951 case OR: {
469952 std::string s = "(";
469953 for (size_t i = 0; i < subs_->size(); i++) {
469954 if (i > 0)
469955 s += "|";
469956 Prefilter* sub = (*subs_)[i];
469957 s += sub ? sub->DebugString() : "<nil>";
469958 }
469959 s += ")";
469960 return s;
469961 }
469962 }
469963}
GMat sub(const GMat &src1, const GMat &src2, int ddepth=-1)

◆ And()

Prefilter * duckdb_re2::Prefilter::And ( Prefilter * a,
Prefilter * b )
staticprivate
469416 {
469417 return AndOr(AND, a, b);
469418}

◆ Or()

Prefilter * duckdb_re2::Prefilter::Or ( Prefilter * a,
Prefilter * b )
staticprivate
469420 {
469421 return AndOr(OR, a, b);
469422}

◆ AndOr()

Prefilter * duckdb_re2::Prefilter::AndOr ( Op op,
Prefilter * a,
Prefilter * b )
staticprivate
469356 {
469357 // If a, b can be rewritten as op, do so.
469358 a = a->Simplify();
469359 b = b->Simplify();
469360
469361 // Canonicalize: a->op <= b->op.
469362 if (a->op() > b->op()) {
469363 Prefilter* t = a;
469364 a = b;
469365 b = t;
469366 }
469367
469368 // Trivial cases.
469369 // ALL AND b = b
469370 // NONE OR b = b
469371 // ALL OR b = ALL
469372 // NONE AND b = NONE
469373 // Don't need to look at b, because of canonicalization above.
469374 // ALL and NONE are smallest opcodes.
469375 if (a->op() == ALL || a->op() == NONE) {
469376 if ((a->op() == ALL && op == AND) ||
469377 (a->op() == NONE && op == OR)) {
469378 delete a;
469379 return b;
469380 } else {
469381 delete b;
469382 return a;
469383 }
469384 }
469385
469386 // If a and b match op, merge their contents.
469387 if (a->op() == op && b->op() == op) {
469388 for (size_t i = 0; i < b->subs()->size(); i++) {
469389 Prefilter* bb = (*b->subs())[i];
469390 a->subs()->push_back(bb);
469391 }
469392 b->subs()->clear();
469393 delete b;
469394 return a;
469395 }
469396
469397 // If a already has the same op as the op that is under construction
469398 // add in b (similarly if b already has the same op, add in a).
469399 if (b->op() == op) {
469400 Prefilter* t = a;
469401 a = b;
469402 b = t;
469403 }
469404 if (a->op() == op) {
469405 a->subs()->push_back(b);
469406 return a;
469407 }
469408
469409 // Otherwise just return the op.
469410 Prefilter* c = new Prefilter(op);
469411 c->subs()->push_back(a);
469412 c->subs()->push_back(b);
469413 return c;
469414}
GOpaque< Size > size(const GMat &src)

◆ FromRegexp()

Prefilter * duckdb_re2::Prefilter::FromRegexp ( Regexp * a)
staticprivate
469912 {
469913 if (re == NULL)
469914 return NULL;
469915
469916 Regexp* simple = re->Simplify();
469917 if (simple == NULL)
469918 return NULL;
469919
469920 Prefilter::Info* info = BuildInfo(simple);
469921 simple->Decref();
469922 if (info == NULL)
469923 return NULL;
469924
469925 Prefilter* m = info->TakeMatch();
469926 delete info;
469927 return m;
469928}

◆ FromString()

Prefilter * duckdb_re2::Prefilter::FromString ( const std::string & str)
staticprivate
469481 {
469482 Prefilter* m = new Prefilter(Prefilter::ATOM);
469483 m->atom_ = str;
469484 return m;
469485}

◆ OrStrings()

Prefilter * duckdb_re2::Prefilter::OrStrings ( SSet * ss)
staticprivate
469454 {
469455 Prefilter* or_prefilter = new Prefilter(NONE);
469456 SimplifyStringSet(ss);
469457 for (SSIter i = ss->begin(); i != ss->end(); ++i)
469458 or_prefilter = Or(or_prefilter, FromString(*i));
469459 return or_prefilter;
469460}

◆ BuildInfo()

Prefilter::Info * duckdb_re2::Prefilter::BuildInfo ( Regexp * re)
staticprivate
469777 {
469778 bool latin1 = (re->parse_flags() & Regexp::Latin1) != 0;
469779 Prefilter::Info::Walker w(latin1);
469780 Prefilter::Info* info = w.WalkExponential(re, NULL, 100000);
469781
469782 if (w.stopped_early()) {
469783 delete info;
469784 return NULL;
469785 }
469786
469787 return info;
469788}

◆ Simplify()

Prefilter * duckdb_re2::Prefilter::Simplify ( )
private
469327 {
469328 if (op_ != AND && op_ != OR) {
469329 return this;
469330 }
469331
469332 // Nothing left in the AND/OR.
469333 if (subs_->empty()) {
469334 if (op_ == AND)
469335 op_ = ALL; // AND of nothing is true
469336 else
469337 op_ = NONE; // OR of nothing is false
469338
469339 return this;
469340 }
469341
469342 // Just one subnode: throw away wrapper.
469343 if (subs_->size() == 1) {
469344 Prefilter* a = (*subs_)[0];
469345 subs_->clear();
469346 delete this;
469347 return a->Simplify();
469348 }
469349
469350 return this;
469351}

◆ SimplifyStringSet()

void duckdb_re2::Prefilter::SimplifyStringSet ( SSet * ss)
staticprivate
469424 {
469425 // Now make sure that the strings aren't redundant. For example, if
469426 // we know "ab" is a required string, then it doesn't help at all to
469427 // know that "abc" is also a required string, so delete "abc". This
469428 // is because, when we are performing a string search to filter
469429 // regexps, matching "ab" will already allow this regexp to be a
469430 // candidate for match, so further matching "abc" is redundant.
469431 // Note that we must ignore "" because find() would find it at the
469432 // start of everything and thus we would end up erasing everything.
469433 //
469434 // The SSet sorts strings by length, then lexicographically. Note that
469435 // smaller strings appear first and all strings must be unique. These
469436 // observations let us skip string comparisons when possible.
469437 SSIter i = ss->begin();
469438 if (i != ss->end() && i->empty()) {
469439 ++i;
469440 }
469441 for (; i != ss->end(); ++i) {
469442 SSIter j = i;
469443 ++j;
469444 while (j != ss->end()) {
469445 if (j->size() > i->size() && j->find(*i) != std::string::npos) {
469446 j = ss->erase(j);
469447 continue;
469448 }
469449 ++j;
469450 }
469451 }
469452}

◆ CrossProduct()

void duckdb_re2::Prefilter::CrossProduct ( const SSet & a,
const SSet & b,
SSet * dst )
staticprivate
469576 {
469577 for (ConstSSIter i = a.begin(); i != a.end(); ++i)
469578 for (ConstSSIter j = b.begin(); j != b.end(); ++j)
469579 dst->insert(*i + *j);
469580}

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