📄 stats.h
字号:
/* * ASTL - the Automaton Standard Template Library. * C++ generic components for Finite State Automata handling. * Copyright (C) 2000-2003 Vincent Le Maout (vincent.lemaout@chello.fr). * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */#ifndef ASTL_STATS_ALGORITHM#define ASTL_STATS_ALGORITHM#include <ccopy.h>struct DFA_stats{ typedef unsigned long State; unsigned long _state_count, _trans_count, _final_states; State null_state; DFA_stats() : _state_count(0), _trans_count(0), _final_states(0), null_state(0) { } State new_state() { return ++_state_count; } template <class Alphabet> void set_trans(State from, const Alphabet &, State to) { ++_trans_count; } struct bool_reference { State q; DFA_stats &dfa; bool_reference(State p, DFA_stats &a) : q(p), dfa(a) { } bool_reference& operator= (bool b) { if (b == true) ++dfa._final_states; return *this; } }; bool_reference final(State q) { return bool_reference(q, *this); } unsigned long state_count() const { return _state_count; } unsigned long trans_count() const { return _trans_count; } unsigned long final_count() const { return _final_states; }};template <typename DFirstCursor>int word_count(DFirstCursor first, DFirstCursor last = DFirstCursor()){ int count = 0; if (first != last && first.src_final()) ++count; while (first != last) { do if (first.aim_final()) ++count; while (first.forward()); while (!first.forward()); } return count;} #endif // ASTL_STATS_ALGORITHM
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -