1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
---|
2 | * JFlex 1.4.3 *
|
---|
3 | * Copyright (C) 1998-2009 Gerwin Klein <[email protected]> *
|
---|
4 | * All rights reserved. *
|
---|
5 | * *
|
---|
6 | * This program is free software; you can redistribute it and/or modify *
|
---|
7 | * it under the terms of the GNU General Public License. See the file *
|
---|
8 | * COPYRIGHT for more information. *
|
---|
9 | * *
|
---|
10 | * This program is distributed in the hope that it will be useful, *
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
---|
13 | * GNU General Public License for more details. *
|
---|
14 | * *
|
---|
15 | * You should have received a copy of the GNU General Public License along *
|
---|
16 | * with this program; if not, write to the Free Software Foundation, Inc., *
|
---|
17 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
---|
18 | * *
|
---|
19 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
---|
20 |
|
---|
21 | package JFlex;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * A list of pairs of states. Used in DFA minimization.
|
---|
25 | *
|
---|
26 | * @author Gerwin Klein
|
---|
27 | * @version JFlex 1.4.3, $Revision: 433 $, $Date: 2009-01-31 19:52:34 +1100 (Sat, 31 Jan 2009) $
|
---|
28 | */
|
---|
29 | final public class StatePairList {
|
---|
30 |
|
---|
31 | // implemented as two arrays of integers.
|
---|
32 | // java.util classes proved too inefficient.
|
---|
33 |
|
---|
34 | int p [];
|
---|
35 | int q [];
|
---|
36 |
|
---|
37 | int num;
|
---|
38 |
|
---|
39 | public StatePairList() {
|
---|
40 | p = new int [8];
|
---|
41 | q = new int [8];
|
---|
42 | num = 0;
|
---|
43 | }
|
---|
44 |
|
---|
45 | public void addPair(int i, int j) {
|
---|
46 | for (int x = 0; x < num; x++)
|
---|
47 | if (p[x] == i && q[x] == j) return;
|
---|
48 |
|
---|
49 | if (num >= p.length) increaseSize(num);
|
---|
50 |
|
---|
51 | p[num] = i;
|
---|
52 | q[num] = j;
|
---|
53 |
|
---|
54 | num++;
|
---|
55 | }
|
---|
56 |
|
---|
57 | public void markAll(StatePairList [] [] list, boolean [] [] equiv) {
|
---|
58 | for (int x = 0; x < num; x++) {
|
---|
59 | int i = p[x];
|
---|
60 | int j = q[x];
|
---|
61 |
|
---|
62 | if (equiv[i][j]) {
|
---|
63 | equiv[i][j] = false;
|
---|
64 | if (list[i][j] != null)
|
---|
65 | list[i][j].markAll(list, equiv);
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | private void increaseSize(int length) {
|
---|
71 | length = Math.max(length+1, 4*p.length);
|
---|
72 | Out.debug("increasing length to "+length); //$NON-NLS-1$
|
---|
73 |
|
---|
74 | int pn [] = new int[length];
|
---|
75 | int qn [] = new int[length];
|
---|
76 |
|
---|
77 | System.arraycopy(p, 0, pn, 0, p.length);
|
---|
78 | System.arraycopy(q, 0, qn, 0, q.length);
|
---|
79 |
|
---|
80 | p = pn;
|
---|
81 | q = qn;
|
---|
82 | }
|
---|
83 | }
|
---|