Macaulay2 Engine
Loading...
Searching...
No Matches

◆ leftOverlaps() [1/2]

auto SuffixTree::leftOverlaps ( const Word & w,
std::vector< std::pair< int, int > > & output,
bool avoidLast = false ) const->void

Definition at line 595 of file SuffixTree.cpp.

598{
599 auto tmpNode = mRoot;
600 auto tmpLabel = w;
601 auto match = findMatch(tmpNode,tmpLabel);
602 auto f = std::get<0>(match);
603 auto pre = std::get<1>(match);
604 int patternNum = -1;
605 while (f != nullptr && pre == Word(f->arcLabel()))
606 {
607 // in this case, the prefix found matches the arc label, so we move down
608 // the tree
609 tmpNode = f;
610 tmpLabel = suffix(tmpLabel,pre.size());
611 // after we move down add all children of tmpNode that are suffix leaves to leftOverlaps
612 // as long as tmpNode is not the root
613 for (auto i = tmpNode->childrenBegin(); i != tmpNode->childrenEnd(); ++i)
614 {
615 if (i->second->isLeaf() && !i->second->isFullPattern())
616 {
617 patternNum = i->second->getPatternNumber();
618 if (!(avoidLast && patternNum == mMonomials.size()-1))
619 output.push_back(std::make_pair(patternNum,
620 mMonomials[patternNum].size()-tmpNode->label().size()));
621 }
622 }
623 match = findMatch(tmpNode,tmpLabel);
624 f = std::get<0>(match);
625 pre = std::get<1>(match);
626 }
627 // At this point, if pre != {} then there is a common prefix to a child, but
628 // the label is not a full match to s. In this case, we add
629 // the unique suffix leaf that shares a prefix to our list,
630 // as long as it is not a full pattern
631 if (pre.size() != 0 && !f->isFullPattern())
632 {
633 patternNum = f->getPatternNumber();
634 if (!(avoidLast && patternNum == mMonomials.size()-1))
635 output.push_back(std::make_pair(patternNum,mMonomials[patternNum].size()-pre.size()));
636 }
637 return;
638}
Word suffix(const Word vec, int indexOfSuffix)
auto findMatch(SuffixTreeNode *y, const Word &s) const -> ExtendedLocusType
SuffixTreeNode * mRoot
std::vector< Label > mMonomials

References findMatch(), mMonomials, mRoot, and suffix().