~ubuntu-branches/ubuntu/gutsy/jflex/gutsy

« back to all changes in this revision

Viewing changes to src/JFlex/StatePairList.java

  • Committer: Bazaar Package Importer
  • Author(s): Takashi Okamoto
  • Date: 2002-02-16 13:38:21 UTC
  • Revision ID: james.westby@ubuntu.com-20020216133821-5wsdprpt9xl7ondr
Tags: upstream-1.3.5
ImportĀ upstreamĀ versionĀ 1.3.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 
2
 * JFlex 1.3.5                                                             *
 
3
 * Copyright (C) 1998-2001  Gerwin Klein <lsf@jflex.de>                    *
 
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
import java.util.*;
 
24
 
 
25
/**
 
26
 * A list of pairs of states. Used in DFA minimization.
 
27
 *
 
28
 * @author Gerwin Klein
 
29
 * @version JFlex 1.3.5, $Revision: 1.14 $, $Date: 2001/10/08 10:08:06 $
 
30
 */
 
31
final public class StatePairList {
 
32
 
 
33
  // implemented as two arrays of integers.
 
34
  // java.util classes proved too inefficient.
 
35
 
 
36
  int p [];
 
37
  int q [];
 
38
  
 
39
  int num;
 
40
 
 
41
  public StatePairList() {
 
42
    p = new int [1];
 
43
    q = new int [1];
 
44
    num = 0;
 
45
  }
 
46
 
 
47
  public void addPair(int i, int j) {
 
48
    for (int x = 0; x < num; x++)
 
49
      if (p[x] == i && q[x] == j) return;
 
50
 
 
51
    ensureSize(num);
 
52
 
 
53
    p[num] = i;
 
54
    q[num] = j;
 
55
    
 
56
    num++;
 
57
  }
 
58
 
 
59
  public void markAll(StatePairList [] [] list, boolean [] [] equiv) {
 
60
    for (int x = 0; x < num; x++) {
 
61
      int i = p[x];
 
62
      int j = q[x];
 
63
      
 
64
      if (equiv[i][j]) {
 
65
        equiv[i][j] = false;
 
66
        if (list[i][j] != null) 
 
67
          list[i][j].markAll(list, equiv);
 
68
      }
 
69
    }
 
70
  }
 
71
 
 
72
  private void ensureSize(int length) {
 
73
    if ( p.length > length ) return;
 
74
                               
 
75
    length = Math.max(length+1, 2*p.length);
 
76
                               
 
77
    int pn [] = new int[length];
 
78
    int qn [] = new int[length];
 
79
 
 
80
    System.arraycopy(p, 0, pn, 0, p.length);
 
81
    System.arraycopy(q, 0, qn, 0, q.length);
 
82
 
 
83
    p = pn; 
 
84
    q = qn;
 
85
  } 
 
86
}