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

◆ subwords() [1/2]

auto SuffixTree::subwords ( const Word & w,
std::vector< std::pair< int, int > > & output,
bool onlyFirst ) const->bool

Definition at line 477 of file SuffixTree.cpp.

480{
481 // this command returns a pair (i,j) where word i in the table appears
482 // in position j of word.
483 auto cLocus = mRoot;
484 auto beta = Word();
485 Word tmpLabel = w;
486 int pos = 0;
487 bool retval = false;
488 std::cout << *(this->mRoot) << std::endl;
489 std::cout << w << std::endl;
490 while (tmpLabel.size() != 0)
491 {
492 SubwordsType swType;
493 if (cLocus == mRoot)
494 swType = subwordsStepD(mRoot,tmpLabel);
495 else
496 swType = subwordsStepC(cLocus->suffixLink(),beta,tmpLabel);
497 auto newcLocus = std::get<0>(swType);
498 auto newbeta = std::get<1>(swType);
499 auto leaf = std::get<2>(swType);
500 auto wasPattern = std::get<3>(swType);
501 //if (wasPattern && isPatternPrefix(leaf->label(),tmpLabel,newcLocus->label().size()+newbeta.size()))
502 if (wasPattern && isPatternPrefix(Word(leaf->label()),tmpLabel))
503 {
504 std::cout << Word(leaf->label()) << " " << tmpLabel << std::endl << std::flush;
505 auto tmp = std::make_pair(leaf->getPatternNumber(),pos);
506 output.push_back(tmp);
507 retval = true;
508 if (onlyFirst) return true;
509 }
510 pos++;
511 cLocus = newcLocus;
512 beta = newbeta;
513 tmpLabel = suffix(tmpLabel,1);
514 std::cout << *cLocus << " " << tmpLabel << std::endl;
515 }
516 return retval;
517}
bool isPatternPrefix(const Word a, const Word b, int startIndex)
Word suffix(const Word vec, int indexOfSuffix)
std::tuple< SuffixTreeNode *, Word, SuffixTreeNode *, bool > SubwordsType
auto subwordsStepC(SuffixTreeNode *x, const Word &beta, const Word &s) const -> SubwordsType
SuffixTreeNode * mRoot
auto subwordsStepD(SuffixTreeNode *y, const Word &s) const -> SubwordsType
int size() const
Definition Word.hpp:74
const mpreal beta(const mpreal &z, const mpreal &w, mp_rnd_t rnd_mode=mpreal::get_default_rnd())
Definition mpreal.h:2357

References isPatternPrefix(), mRoot, Word::size(), subwordsStepC(), subwordsStepD(), and suffix().