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

◆ insertStepD()

auto SuffixTree::insertStepD ( SuffixTreeNode * y,
const Word & s,
bool isFullPattern )->InsertType

Definition at line 259 of file SuffixTree.cpp.

262{
263 // Carries out step D in the algorithm. This amounts to constructing
264 // the locus of the head of s (which is not yet known before calling this function).
265 // find the contracted locus of s, starting from the node y
266 auto clType = contractedLocus(y,s,isFullPattern);
267 auto newy = std::get<0>(clType);
268 auto f = std::get<1>(clType);
269 auto pre = std::get<2>(clType);
270 auto tmpNode = y;
271 auto tmpLabel = s;
272
273 // drop the letters from s along the path traversed from y to std::get<0>(clType);
274 tmpLabel = suffix(tmpLabel, newy->label().size() - tmpNode->label().size());
275 tmpNode = newy;
276 if (f == nullptr)
277 {
278 // in this case, there is no common prefix of a label of any child of y and s
279 // so just create a leaf immediately.
280 auto v = new SuffixTreeNode(tmpNode,tmpLabel,isFullPattern);
281 if (tmpNode->label().size() != 0 && v->arcLabel().size() == 1)
282 return std::make_tuple(tmpNode,tmpNode,v);
283 else
284 return std::make_tuple(tmpNode,nullptr,v);
285 }
286 // in this case, f is the extended locus of s. We need to split the arc from y to f
287 auto p = splitArc(f,pre);
288 // update the patternLeafCount of p if necessary
289 p->setPatternLeafCount(f->patternLeafCount());
290 p->addToPatternLeafCount(isFullPattern);
291 p->addToPatternLeafCount(f->isFullPattern());
292 // drop common prefix
293 tmpLabel = suffix(tmpLabel,pre.size());
294 // create new leaf under p for s
295 auto w = new SuffixTreeNode (p,tmpLabel,isFullPattern);
296 // return overlap and head information
297 if (tmpLabel.size() == 1)
298 return std::make_tuple(p,p,w);
299 else
300 return std::make_tuple(p,nullptr,w);
301}
Word suffix(const Word vec, int indexOfSuffix)
auto contractedLocus(SuffixTreeNode *y, const Word &s, bool incrementLeafCount=false) const -> ContractedLocusType
auto splitArc(SuffixTreeNode *f, const Word &prefix) -> SuffixTreeNode *
int p
void size_t s
Definition m2-mem.cpp:271

References contractedLocus(), p, s, splitArc(), and suffix().

Referenced by insert(), insertStepC(), and insertWorker().