| 2807 | } |
| 2808 | |
| 2809 | void Pattern::compact_dfa(DFA::State *start) |
| 2810 | { |
| 2811 | #if WITH_COMPACT_DFA == -1 |
| 2812 | // edge compaction in reverse order |
| 2813 | for (DFA::State *state = start; state != NULL; state = state->next) |
| 2814 | { |
| 2815 | for (DFA::State::Edges::iterator i = state->edges.begin(); i != state->edges.end(); ++i) |
| 2816 | { |
| 2817 | Char hi = i->second.first; |
| 2818 | if (hi >= 0xff) |
| 2819 | break; |
| 2820 | DFA::State::Edges::iterator j = i; |
| 2821 | ++j; |
| 2822 | while (j != state->edges.end() && j->first <= hi + 1) |
| 2823 | { |
| 2824 | hi = j->second.first; |
| 2825 | if (j->second.second == i->second.second) |
| 2826 | { |
| 2827 | i->second.first = hi; |
| 2828 | state->edges.erase(j++); |
| 2829 | } |
| 2830 | else |
| 2831 | { |
| 2832 | ++j; |
| 2833 | } |
| 2834 | } |
| 2835 | } |
| 2836 | } |
| 2837 | #elif WITH_COMPACT_DFA == 1 |
| 2838 | // edge compaction |
| 2839 | for (DFA::State *state = start; state != NULL; state = state->next) |
| 2840 | { |
| 2841 | for (DFA::State::Edges::reverse_iterator i = state->edges.rbegin(); i != state->edges.rend(); ++i) |
| 2842 | { |
| 2843 | Char lo = i->second.first; |
| 2844 | if (lo <= 0x00) |
| 2845 | break; |
| 2846 | DFA::State::Edges::reverse_iterator j = i; |
| 2847 | ++j; |
| 2848 | while (j != state->edges.rend() && j->first >= lo - 1) |
| 2849 | { |
| 2850 | lo = j->second.first; |
| 2851 | if (j->second.second == i->second.second) |
| 2852 | { |
| 2853 | i->second.first = lo; |
| 2854 | state->edges.erase(--j.base()); |
| 2855 | } |
| 2856 | else |
| 2857 | { |
| 2858 | ++j; |
| 2859 | } |
| 2860 | } |
| 2861 | } |
| 2862 | } |
| 2863 | #else |
| 2864 | (void)start; |
| 2865 | #endif |
| 2866 | } |