本文整理汇总了C++中NFA::setAlphabetSet方法的典型用法代码示例。如果您正苦于以下问题:C++ NFA::setAlphabetSet方法的具体用法?C++ NFA::setAlphabetSet怎么用?C++ NFA::setAlphabetSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NFA
的用法示例。
在下文中一共展示了NFA::setAlphabetSet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getNFA_Star
NFA getNFA_Star(NFA nfa) {
int head = 0;
int tail = 1;
int offset = 2;
int start = nfa.start_state + offset;
vector<State> states;
NFA ret;
ret.setAlphabetSet(nfa.alphabet);
ret.setStartState(head);
ret.setTransFunc(head, map<char, vector<int> >());
ret.setTransFunc(tail, map<char, vector<int> >());
states.push_back(State(false));
states.push_back(State(true));
for(int i = 0; i < nfa.states.size(); i++) {
ret.setTransFunc(i+offset, nfa.trans_func[i]);
for(map<char, vector<int> >::iterator it = ret.trans_func[i+offset].begin();
it != ret.trans_func[i+offset].end(); it++) {
for(vector<int>::iterator jt = it->second.begin();
jt != it->second.end(); jt++) {
*jt = *jt + offset;
}
}
states.push_back(State(false));
if(nfa.states[i].isAccepted()) {
ret.trans_func[i + offset][NFA::lambda].push_back(start);
ret.trans_func[i + offset][NFA::lambda].push_back(tail);
}
}
if(find(ret.alphabet.begin(), ret.alphabet.end(), NFA::lambda) == ret.alphabet.end())
ret.alphabet.push_back(NFA::lambda);
ret.trans_func[head][NFA::lambda].push_back(start);
ret.setStateSet(states);
return ret;
}
示例2: getNFAbyString
NFA getNFAbyString(const char str[]) {
NFA ret;
ret.setStartState(0);
vector<State> states;
vector<char> alphabets;
int len = strlen(str);
set<char> S;
for(int i = 0; i < len; i++) {
map<char, vector<int> > trans_func;
trans_func[str[i]].push_back(i+1);
states.push_back(State());
ret.setTransFunc(i, trans_func);
if(S.find(str[i]) == S.end())
S.insert(str[i]), alphabets.push_back(str[i]);
}
ret.setTransFunc(len, map<char, vector<int> >());
states.push_back(State(true));
ret.setStateSet(states);
ret.setAlphabetSet(alphabets);
return ret;
}