/[bison]/bison/src/warshall.c
ViewVC logotype

Diff of /bison/src/warshall.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.9 by akim, Thu Dec 13 11:02:20 2001 UTC revision 1.10 by akim, Mon Mar 4 12:03:01 2002 UTC
# Line 1  Line 1 
1  /* Generate transitive closure of a matrix,  /* Generate transitive closure of a matrix,
2     Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc.     Copyright 1984, 1989, 2000, 2001, 2002 Free Software Foundation, Inc.
3    
4     This file is part of Bison, the GNU Compiler Compiler.     This file is part of Bison, the GNU Compiler Compiler.
5    
# Line 21  Line 21 
21    
22  #include "system.h"  #include "system.h"
23  #include "getargs.h"  #include "getargs.h"
24    #include "bitset.h"
25  #include "warshall.h"  #include "warshall.h"
26    
27  /*-------------------------------------------------------------.  /*--------------------------------------------------------.
28  | Given n by n matrix of bits R, modify its contents to be the |  | Display the MATRIX array of SIZE bitsets of size SIZE.  |
29  | transive closure of what was given.                          |  `--------------------------------------------------------*/
 `-------------------------------------------------------------*/  
30    
31  static void  static void
32  bitmatrix_print (const char *title, unsigned *matrix, size_t size)  bitmatrix_print (const char *title, bitset *matrix, size_t size)
33  {  {
34    size_t i, j;    size_t i, j;
   size_t rowsize = WORDSIZE (size) * sizeof (unsigned);  
 #define ROW(Num) ((unsigned *) ((char *) matrix + ((Num) * rowsize)))  
35    
36    /* Title. */    /* Title. */
37    fprintf (stderr, "%s BEGIN\n", title);    fprintf (stderr, "%s BEGIN\n", title);
# Line 59  bitmatrix_print (const char *title, unsi Line 57  bitmatrix_print (const char *title, unsi
57      {      {
58        fprintf (stderr, "%2d|", i);        fprintf (stderr, "%2d|", i);
59        for (j = 0; j < size; ++j)        for (j = 0; j < size; ++j)
60          fputs (BITISSET (ROW (i), j) ? "1" : " ", stderr);          fputs (bitset_test (matrix[i], j) ? "1" : " ", stderr);
61        fputs ("|\n", stderr);        fputs ("|\n", stderr);
62      }      }
63    
# Line 73  bitmatrix_print (const char *title, unsi Line 71  bitmatrix_print (const char *title, unsi
71    fprintf (stderr, "%s END\n\n", title);    fprintf (stderr, "%s END\n\n", title);
72  }  }
73    
74  #define R(Num) (unsigned *) ((char *) R + ((Num) * rowsize))  /*-------------------------------------------------------------------.
75    | Given the MATRIX array of N bitsets of size N, modify its contents |
76    | to be the transive closure of what was given.                      |
77    `-------------------------------------------------------------------*/
78    
79  static void  static void
80  TC (unsigned *R, int n)  TC (bitset *matrix, int n)
81  {  {
   int rowsize = WORDSIZE (n) * sizeof (unsigned);  
82    int i, j, k;    int i, j, k;
83    
84    if (trace_flag)    if (trace_flag)
85      bitmatrix_print ("TC: Input", R, n);      bitmatrix_print ("TC: Input", matrix, n);
86    
87    /* R (J, I) && R (I, K) => R (J, K).    /* R (J, I) && R (I, K) => R (J, K).
88       I *must* be the outter loop. */       I *must* be the outter loop. */
89    
90    for (i = 0; i < n; ++i)    for (i = 0; i < n; ++i)
91      for (j = 0; j < n; ++j)      for (j = 0; j < n; ++j)
92        if (BITISSET (R (j), i))        if (bitset_test (matrix[j], i))
93          for (k = 0; k < n; ++k)          for (k = 0; k < n; ++k)
94            if (BITISSET (R (i), k))            if (bitset_test (matrix[i], k))
95              SETBIT (R (j), k);              bitset_set (matrix[j], k);
96    
97    if (trace_flag)    if (trace_flag)
98      bitmatrix_print ("TC: Output", R, n);      bitmatrix_print ("TC: Output", matrix, n);
99  }  }
100    
101    
102  /*---------------------------------------------------------------.  /*---------------------------------------------------------------.
103  | Reflexive Transitive Closure.  Same as TC and then set all the |  | Reflexive Transitive Closure.  Same as TC and then set all the |
104  | bits on the diagonal of R.                                     |  | bits on the diagonal of MATRIX.                                |
105  `---------------------------------------------------------------*/  `---------------------------------------------------------------*/
106    
107  void  void
108  RTC (unsigned *R, int n)  RTC (bitset *matrix, int n)
109  {  {
   int rowsize = WORDSIZE (n) * sizeof (unsigned);  
110    int i;    int i;
111    
112    TC (R, n);    TC (matrix, n);
113    for (i = 0; i < n; ++i)    for (i = 0; i < n; ++i)
114      SETBIT (R (i), i);      bitset_set (matrix[i], i);
115  }  }

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26