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

Public Member Functions

 BitState (Prog *prog)
bool Search (const StringPiece &text, const StringPiece &context, bool anchored, bool longest, StringPiece *submatch, int nsubmatch)

Private Member Functions

bool ShouldVisit (int id, const char *p)
void Push (int id, const char *p)
void GrowStack ()
bool TrySearch (int id, const char *p)
 BitState (const BitState &)=delete
BitState & operator= (const BitState &)=delete

Private Attributes

Prog * prog_
StringPiece text_
StringPiece context_
bool anchored_
bool longest_
bool endmatch_
StringPiece * submatch_
int nsubmatch_
PODArray< uint64_t > visited_
PODArray< const char * > cap_
PODArray< Job > job_
int njob_

Static Private Attributes

static constexpr int kVisitedBits = 64

Constructor & Destructor Documentation

◆ BitState()

duckdb_re2::BitState::BitState ( Prog * prog)
explicit
460288 : prog_(prog),
460289 anchored_(false),
460290 longest_(false),
460291 endmatch_(false),
460292 submatch_(NULL),
460293 nsubmatch_(0),
460294 njob_(0) {
460295}

Member Function Documentation

◆ Search()

bool duckdb_re2::BitState::Search ( const StringPiece & text,
const StringPiece & context,
bool anchored,
bool longest,
StringPiece * submatch,
int nsubmatch )
460501 {
460502 // Search parameters.
460503 text_ = text;
460504 context_ = context;
460505 if (context_.data() == NULL)
460506 context_ = text;
460507 if (prog_->anchor_start() && BeginPtr(context_) != BeginPtr(text))
460508 return false;
460509 if (prog_->anchor_end() && EndPtr(context_) != EndPtr(text))
460510 return false;
460511 anchored_ = anchored || prog_->anchor_start();
460512 longest_ = longest || prog_->anchor_end();
460513 endmatch_ = prog_->anchor_end();
460514 submatch_ = submatch;
460515 nsubmatch_ = nsubmatch;
460516 for (int i = 0; i < nsubmatch_; i++)
460517 submatch_[i] = StringPiece();
460518
460519 // Allocate scratch space.
460520 int nvisited = prog_->list_count() * static_cast<int>(text.size()+1);
460521 nvisited = (nvisited + kVisitedBits-1) / kVisitedBits;
460522 visited_ = PODArray<uint64_t>(nvisited);
460523 memset(visited_.data(), 0, nvisited*sizeof visited_[0]);
460524
460525 int ncap = 2*nsubmatch;
460526 if (ncap < 2)
460527 ncap = 2;
460528 cap_ = PODArray<const char*>(ncap);
460529 memset(cap_.data(), 0, ncap*sizeof cap_[0]);
460530
460531 // When sizeof(Job) == 16, we start with a nice round 1KiB. :)
460532 job_ = PODArray<Job>(64);
460533
460534 // Anchored search must start at text.begin().
460535 if (anchored_) {
460536 cap_[0] = text.data();
460537 return TrySearch(prog_->start(), text.data());
460538 }
460539
460540 // Unanchored search, starting from each possible text position.
460541 // Notice that we have to try the empty string at the end of
460542 // the text, so the loop condition is p <= text.end(), not p < text.end().
460543 // This looks like it's quadratic in the size of the text,
460544 // but we are not clearing visited_ between calls to TrySearch,
460545 // so no work is duplicated and it ends up still being linear.
460546 const char* etext = text.data() + text.size();
460547 for (const char* p = text.data(); p <= etext; p++) {
460548 // Try to use prefix accel (e.g. memchr) to skip ahead.
460549 if (p < etext && prog_->can_prefix_accel()) {
460550 p = reinterpret_cast<const char*>(prog_->PrefixAccel(p, etext - p));
460551 if (p == NULL)
460552 p = etext;
460553 }
460554
460555 cap_[0] = p;
460556 if (TrySearch(prog_->start(), p)) // Match must be leftmost; done.
460557 return true;
460558 // Avoid invoking undefined behavior (arithmetic on a null pointer)
460559 // by simply not continuing the loop.
460560 if (p == NULL)
460561 break;
460562 }
460563 return false;
460564}

◆ ShouldVisit()

bool duckdb_re2::BitState::ShouldVisit ( int id,
const char * p )
inlineprivate
460301 {
460302 int n = prog_->list_heads()[id] * static_cast<int>(text_.size()+1) +
460303 static_cast<int>(p-text_.data());
460304 if (visited_[n/kVisitedBits] & (uint64_t{1} << (n & (kVisitedBits-1))))
460305 return false;
460306 visited_[n/kVisitedBits] |= uint64_t{1} << (n & (kVisitedBits-1));
460307 return true;
460308}
::uint64_t uint64_t

◆ Push()

void duckdb_re2::BitState::Push ( int id,
const char * p )
private
460318 {
460319 if (njob_ >= job_.size()) {
460320 GrowStack();
460321 if (njob_ >= job_.size()) {
460322 LOG(DFATAL) << "GrowStack() failed: "
460323 << "njob_ = " << njob_ << ", "
460324 << "job_.size() = " << job_.size();
460325 return;
460326 }
460327 }
460328
460329 // If id < 0, it's undoing a Capture,
460330 // so we mustn't interfere with that.
460331 if (id >= 0 && njob_ > 0) {
460332 Job* top = &job_[njob_-1];
460333 if (id == top->id &&
460334 p == top->p + top->rle + 1 &&
460335 top->rle < std::numeric_limits<int>::max()) {
460336 ++top->rle;
460337 return;
460338 }
460339 }
460340
460341 Job* top = &job_[njob_++];
460342 top->id = id;
460343 top->rle = 0;
460344 top->p = p;
460345}

◆ GrowStack()

void duckdb_re2::BitState::GrowStack ( )
private
460311 {
460312 PODArray<Job> tmp(2*job_.size());
460313 memmove(tmp.data(), job_.data(), njob_*sizeof job_[0]);
460314 job_ = std::move(tmp);
460315}

◆ TrySearch()

bool duckdb_re2::BitState::TrySearch ( int id,
const char * p )
private
460349 {
460350 bool matched = false;
460351 const char* end = text_.data() + text_.size();
460352 njob_ = 0;
460353 // Push() no longer checks ShouldVisit(),
460354 // so we must perform the check ourselves.
460355 if (ShouldVisit(id0, p0))
460356 Push(id0, p0);
460357 while (njob_ > 0) {
460358 // Pop job off stack.
460359 --njob_;
460360 int id = job_[njob_].id;
460361 int& rle = job_[njob_].rle;
460362 const char* p = job_[njob_].p;
460363
460364 if (id < 0) {
460365 // Undo the Capture.
460366 cap_[prog_->inst(-id)->cap()] = p;
460367 continue;
460368 }
460369
460370 if (rle > 0) {
460371 p += rle;
460372 // Revivify job on stack.
460373 --rle;
460374 ++njob_;
460375 }
460376
460377 Loop:
460378 // Visit id, p.
460379 Prog::Inst* ip = prog_->inst(id);
460380 switch (ip->opcode()) {
460381 default:
460382 LOG(DFATAL) << "Unexpected opcode: " << ip->opcode();
460383 return false;
460384
460385 case kInstFail:
460386 break;
460387
460388 case kInstAltMatch:
460389 if (ip->greedy(prog_)) {
460390 // out1 is the Match instruction.
460391 id = ip->out1();
460392 p = end;
460393 goto Loop;
460394 }
460395 if (longest_) {
460396 // ip must be non-greedy...
460397 // out is the Match instruction.
460398 id = ip->out();
460399 p = end;
460400 goto Loop;
460401 }
460402 goto Next;
460403
460404 case kInstByteRange: {
460405 int c = -1;
460406 if (p < end)
460407 c = *p & 0xFF;
460408 if (!ip->Matches(c))
460409 goto Next;
460410
460411 if (ip->hint() != 0)
460412 Push(id+ip->hint(), p); // try the next when we're done
460413 id = ip->out();
460414 p++;
460415 goto CheckAndLoop;
460416 }
460417
460418 case kInstCapture:
460419 if (!ip->last())
460420 Push(id+1, p); // try the next when we're done
460421
460422 if (0 <= ip->cap() && ip->cap() < cap_.size()) {
460423 // Capture p to register, but save old value first.
460424 Push(-id, cap_[ip->cap()]); // undo when we're done
460425 cap_[ip->cap()] = p;
460426 }
460427
460428 id = ip->out();
460429 goto CheckAndLoop;
460430
460431 case kInstEmptyWidth:
460432 if (ip->empty() & ~Prog::EmptyFlags(context_, p))
460433 goto Next;
460434
460435 if (!ip->last())
460436 Push(id+1, p); // try the next when we're done
460437 id = ip->out();
460438 goto CheckAndLoop;
460439
460440 case kInstNop:
460441 if (!ip->last())
460442 Push(id+1, p); // try the next when we're done
460443 id = ip->out();
460444
460445 CheckAndLoop:
460446 // Sanity check: id is the head of its list, which must
460447 // be the case if id-1 is the last of *its* list. :)
460448 DCHECK(id == 0 || prog_->inst(id-1)->last());
460449 if (ShouldVisit(id, p))
460450 goto Loop;
460451 break;
460452
460453 case kInstMatch: {
460454 if (endmatch_ && p != end)
460455 goto Next;
460456
460457 // We found a match. If the caller doesn't care
460458 // where the match is, no point going further.
460459 if (nsubmatch_ == 0)
460460 return true;
460461
460462 // Record best match so far.
460463 // Only need to check end point, because this entire
460464 // call is only considering one start position.
460465 matched = true;
460466 cap_[1] = p;
460467 if (submatch_[0].data() == NULL ||
460468 (longest_ && p > submatch_[0].data() + submatch_[0].size())) {
460469 for (int i = 0; i < nsubmatch_; i++)
460470 submatch_[i] =
460471 StringPiece(cap_[2 * i],
460472 static_cast<size_t>(cap_[2 * i + 1] - cap_[2 * i]));
460473 }
460474
460475 // If going for first match, we're done.
460476 if (!longest_)
460477 return true;
460478
460479 // If we used the entire text, no longer match is possible.
460480 if (p == end)
460481 return true;
460482
460483 // Otherwise, continue on in hope of a longer match.
460484 // Note the absence of the ShouldVisit() check here
460485 // due to execution remaining in the same list.
460486 Next:
460487 if (!ip->last()) {
460488 id++;
460489 goto Loop;
460490 }
460491 break;
460492 }
460493 }
460494 }
460495 return matched;
460496}
cv::Point2i p0
GOpaque< Size > size(const GMat &src)

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