internal static int gdfs(GState s) { GTrans t; GScc c; GScc scc = new GScc(); scc.gstate = s; scc.rank = rank; scc.theta = rank++; scc.nxt = scc_stack; scc_stack = scc; s.incoming = 1; for (t = s.trans.nxt; t != s.trans; t = t.nxt) { if (t.to.incoming == 0) { int result = gdfs(t.to); scc.theta = Math.Min(scc.theta, result); } else { for (c = scc_stack.nxt; c != null; c = c.nxt) { if (c.gstate == t.to) { scc.theta = Math.Min(scc.theta, c.rank); break; } } } } if (scc.rank == scc.theta) { while (scc_stack != scc) { scc_stack.gstate.incoming = scc_id; scc_stack = scc_stack.nxt; } scc.gstate.incoming = scc_id++; scc_stack = scc.nxt; } return(scc.theta); }
internal static void simplify_gscc() { GState s; GTrans t; int i; int[][] scc_final; rank = 1; scc_stack = null; scc_id = 1; if (gstates == gstates.nxt) { return; } for (s = gstates.nxt; s != gstates; s = s.nxt) { s.incoming = 0; /* state color = white */ } for (i = 0; i < init_size; i++) { if (init[i] != null && init[i].incoming == 0) { gdfs(init[i]); } } scc_final = new int[scc_id][]; for (i = 0; i < scc_id; i++) { scc_final[i] = set.make_set(-1, 0); } for (s = gstates.nxt; s != gstates; s = s.nxt) { if (s.incoming == 0) { s = remove_gstate(s, null); } else { for (t = s.trans.nxt; t != s.trans; t = t.nxt) { if (t.to.incoming == s.incoming) { set.merge_sets(scc_final[s.incoming], t.final, 0); } } } } scc_size = (scc_id + 1) / (8 * sizeof(int)) + 1; bad_scc = set.make_set(-1, 2); for (i = 0; i < scc_id; i++) { if (set.included_set(alternating.final_set, scc_final[i], 0) == 0) { set.add_set(bad_scc, i); } } for (i = 0; i < scc_id; i++) { mem.tfree(scc_final[i]); } mem.tfree(scc_final); }