本文整理汇总了C++中DFA::set_move方法的典型用法代码示例。如果您正苦于以下问题:C++ DFA::set_move方法的具体用法?C++ DFA::set_move怎么用?C++ DFA::set_move使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DFA
的用法示例。
在下文中一共展示了DFA::set_move方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateSuffixDFA
void CreateSuffixDFA(DFA& A, typename DFA::state_id_t Root = initial_state) {
typedef typename DFA::state_id_t state_id_t;
typedef typename DFA::transition_t trans_t;
valvec<state_id_t> F, L, Q1, Q2, S(A.total_states(), Root);
state_id_t MostFinal = A.null_state;
S[Root] = A.null_state;
auto SuffixNext = [&](state_id_t p, state_id_t q, byte_t c) {
state_id_t t = A.null_state;
while (p != Root) {
t = A.state_move(p, c);
if (A.null_state == t) {
A.add_move(p, q, c);
p = S[p];
} else
goto Next;
}
assert(A.null_state == t);
A.add_move(Root, q, c);
S[q] = Root;
return;
Next:
if (L[p] + 1 == L[t] && t != q) {
S[q] = t;
} else {
state_id_t r;
if (t == q) {
r = t;
} else {
r = A.clone_state(t);
L.resize(A.total_states(), 0);
S.resize(A.total_states(), Root);
S[q] = r;
}
S[r] = S[t];
S[t] = S[r];
L[r] = L[p] + 1;
assert(A.state_move(p, c) != A.null_state);
while (A.null_state != p &&
L[A.state_move(p, c)] >= L[r])
{
A.set_move(p, r, c);
p = S[p];
}
}
};
auto SuffixFinal = [&](state_id_t p) {
while (A.null_state != (p = S[p]) && !A.is_term(p))
A.set_term_bit(p);
};
ComputeLongestPathLength(A, Root, L);
for (size_t i = 0; i < L.size(); ++i) {
printf("L[%04zd] = %u\n", i, L[i]);
}
valvec<CharTarget<state_id_t> > MostFinal_src;
A.resize_states(A.total_states());
Q1.push_back(Root);
simplebitvec mark(A.total_states());
// valvec<CharTarget<state_id_t> > children;
L.resize(A.total_states());
while (!Q1.empty()) {
for (state_id_t p0 : Q1) {
// children.erase_all();
A.for_each_move(p0,[&](state_id_t p,const trans_t& t,byte_t c){
state_id_t q = t;
bool q_has_children = A.has_children(q);
if (mark.is0(q)) {
if (!q_has_children) {
assert(A.null_state == MostFinal);
assert(A.is_term(q));
MostFinal_src.emplace_back(c, p);
MostFinal = q;
}
if (A.is_term(q))
F.push_back(q);
mark.set1(q);
Q2.push_back(q);
}
if (q_has_children)
SuffixNext(p, q, c);
});
}
Q1.swap(Q2);
Q2.erase_all();
}
assert(A.null_state != MostFinal);
for (auto ct : MostFinal_src) {
state_id_t src = ct.target;
SuffixNext(src, MostFinal, ct.ch);
SuffixFinal(MostFinal);
}
for (state_id_t p : F)
SuffixFinal(p);
}