30 const std::vector<dfa_state_t*> &states,
33 const size_t count = states.size();
35 bool **tbl =
new bool*[count];
36 tbl[0] =
new bool[count * (count - 1) / 2];
37 for (
size_t i = 0; i < count - 1; ++i)
39 tbl[i + 1] = tbl[i] + i;
42 for (
size_t i = 0; i < count; ++i)
45 for (
size_t j = 0; j < i; ++j)
48 tbl[i][j] = s1->
ctx != s2->
ctx
53 for (
bool loop =
true; loop;)
56 for (
size_t i = 0; i < count; ++i)
58 for (
size_t j = 0; j < i; ++j)
62 for (
size_t k = 0; k < nchars; ++k)
64 size_t oi = states[i]->arcs[k];
65 size_t oj = states[j]->arcs[k];
85 for (
size_t i = 0; i < count; ++i)
88 for (
size_t j = 0; j < i; ++j)
115 const std::vector<dfa_state_t*> &states,
118 const size_t count = states.size();
120 size_t *next =
new size_t[count];
122 std::map<std::pair<RuleOp*, bool>,
size_t> init;
123 for (
size_t i = 0; i < count; ++i)
126 std::pair<RuleOp*, bool> key(s->
rule, s->
ctx);
127 if (init.insert(std::make_pair(key, i)).second)
134 const size_t j = init[key];
141 size_t *out =
new size_t[nchars * count];
142 size_t *
diff =
new size_t[count];
143 for (
bool loop =
true; loop;)
146 for (
size_t i = 0; i < count; ++i)
153 for (
size_t j = i; j !=
dfa_t::NIL; j = next[j])
155 size_t *o = &out[j * nchars];
156 size_t *a = states[j]->arcs;
157 for (
size_t c = 0; c < nchars; ++c)
165 size_t diff_count = 0;
168 const size_t j_next = next[j];
170 for (; n < diff_count; ++n)
173 if (memcmp(&out[j * nchars],
175 nchars *
sizeof(
size_t)) == 0)
185 diff[diff_count++] = j;
191 loop |= diff_count > 1;
201 const size_t count = dfa.
states.size();
203 size_t *part =
new size_t[count];
215 size_t *compact =
new size_t[count];
216 for (
size_t i = 0, j = 0; i < count; ++i)
224 size_t new_count = 0;
225 for (
size_t i = 0; i < count; ++i)
230 size_t *arcs = s->
arcs;
231 for (
size_t c = 0; c < dfa.
nchars; ++c)
235 arcs[c] = compact[part[arcs[c]]];
238 dfa.
states[new_count++] = s;
245 dfa.
states.resize(new_count);
std::vector< dfa_state_t * > states
static void minimization_moore(size_t *part, const std::vector< dfa_state_t * > &states, size_t nchars)
static void minimization_table(size_t *part, const std::vector< dfa_state_t * > &states, size_t nchars)
static int32_t diff(const re2c::Range *r1, const re2c::Range *r2, const re2c::Range *op1, const re2c::Range *op2, const char *op)
dfa_minimization_t dfa_minimization
void minimization(dfa_t &dfa)