本文整理汇总了C++中NFA::root方法的典型用法代码示例。如果您正苦于以下问题:C++ NFA::root方法的具体用法?C++ NFA::root怎么用?C++ NFA::root使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NFA
的用法示例。
在下文中一共展示了NFA::root方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processNFAs
void CombinedURLFilters::processNFAs(size_t maxNFASize, std::function<void(NFA&&)> handler)
{
#if CONTENT_EXTENSIONS_STATE_MACHINE_DEBUGGING
print();
#endif
while (true) {
// Traverse out to a leaf.
Vector<PrefixTreeVertex*, 128> stack;
PrefixTreeVertex* vertex = m_prefixTreeRoot.get();
while (true) {
ASSERT(vertex);
stack.append(vertex);
if (vertex->edges.isEmpty())
break;
vertex = vertex->edges.last().child.get();
}
if (stack.size() == 1)
break; // We're done once we have processed and removed all the edges in the prefix tree.
// Find the prefix root for this NFA. This is the vertex after the last term with a quantifier if there is one,
// or the root if there are no quantifiers left.
while (stack.size() > 1) {
if (!stack[stack.size() - 2]->edges.last().term.hasFixedLength())
break;
stack.removeLast();
}
ASSERT_WITH_MESSAGE(!stack.isEmpty(), "At least the root should be in the stack");
// Make an NFA with the subtrees for whom this is also the last quantifier (or who also have no quantifier).
NFA nfa;
// Put the prefix into the NFA.
unsigned prefixEnd = nfa.root();
for (unsigned i = 0; i < stack.size() - 1; ++i) {
ASSERT(!stack[i]->edges.isEmpty());
const PrefixTreeEdge& edge = stack[i]->edges.last();
prefixEnd = edge.term.generateGraph(nfa, prefixEnd, edge.child->finalActions);
}
// Put the non-quantified vertices in the subtree into the NFA and delete them.
ASSERT(stack.last());
generateNFAForSubtree(nfa, prefixEnd, *stack.last(), maxNFASize);
handler(WTF::move(nfa));
// Clean up any processed leaf nodes.
while (true) {
if (stack.size() > 1) {
if (stack[stack.size() - 1]->edges.isEmpty()) {
stack[stack.size() - 2]->edges.removeLast();
stack.removeLast();
} else
break; // Vertex is not a leaf.
} else
break; // Leave the empty root.
}
}
}