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

◆ insertStepC()

auto SuffixTree::insertStepC ( SuffixTreeNode * v,
SuffixTreeNode * x,
const Word & beta,
const Word & s,
bool isFullPattern )->InsertType

Definition at line 223 of file SuffixTree.cpp.

228{
229 // Carries out step C in the algorithm. This amounts to computing (and building,
230 // if necessary) the suffix link of v. This function can call the Step D code
231 // as well (see the algorithm in the paper by Amir, et.al.)
232 auto iwType = extendedLocus(x, beta);
233 auto f = std::get<0>(iwType);
234 auto betaHat = std::get<1>(iwType);
235 if (f->arcLabel().size() == betaHat.size())
236 {
237 // in this case, f is in fact the locus of beta
238 v->setSuffixLink(f);
239 return insertStepD(f,suffix(s,f->label().size()),isFullPattern);
240 }
241 // in this case, f is the extended locus of beta. We need to split
242 // the arc from f to its parent and insert a node d and a child
243 // w which will be the locus of beta
244 auto d = splitArc(f,betaHat);
245 // update pattern leaf count of d
246 d->setPatternLeafCount(f->patternLeafCount());
247 d->addToPatternLeafCount(isFullPattern);
248 d->addToPatternLeafCount(f->isFullPattern());
249 // add in the locus of s
250 auto w = new SuffixTreeNode(d,suffix(s,d->label().size()),isFullPattern);
251 // set the suffix link of v to d
252 v->setSuffixLink(d);
253 if (w->label().size() == 1)
254 return std::make_tuple(d,f,w);
255 else
256 return std::make_tuple(d,nullptr,w);
257}
Word suffix(const Word vec, int indexOfSuffix)
auto insertStepD(SuffixTreeNode *y, const Word &s, bool isFullPattern) -> InsertType
auto extendedLocus(SuffixTreeNode *x, const Word &beta) const -> ExtendedLocusType
auto splitArc(SuffixTreeNode *f, const Word &prefix) -> SuffixTreeNode *
void setSuffixLink(SuffixTreeNode *newSuffixLink)
void size_t s
Definition m2-mem.cpp:271
volatile int x

References extendedLocus(), insertStepD(), s, splitArc(), suffix(), and x.

Referenced by insert(), and insertWorker().