/[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.6 by akim, Tue Nov 7 16:28:47 2000 UTC revision 1.6.2.1 by akim, Wed Dec 5 09:23:10 2001 UTC
# Line 1  Line 1 
1  /* Generate transitive closure of a matrix,  /* Generate transitive closure of a matrix,
2     Copyright 1984, 1989, 2000 Free Software Foundation, Inc.     Copyright 1984, 1989, 2000, 2001 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 22  Line 22 
22  #include "system.h"  #include "system.h"
23  #include "warshall.h"  #include "warshall.h"
24    
25  /* Given n by n matrix of bits R, modify its contents to be the  /*-------------------------------------------------------------.
26     transive closure of what was given.  */  | Given n by n matrix of bits R, modify its contents to be the |
27    | transive closure of what was given.                          |
28    `-------------------------------------------------------------*/
29    
30    #define R(Num) (unsigned *) ((char *) R + ((Num) * rowsize))
31    
32  static void  static void
33  TC (unsigned *R, int n)  TC (unsigned *R, int n)
34  {  {
35    int rowsize;    int rowsize = WORDSIZE (n) * sizeof (unsigned);
36    unsigned mask;    int i, j, k;
   unsigned *rowj;  
   unsigned *rp;  
   unsigned *rend;  
   unsigned *ccol;  
   
   unsigned *relend;  
   unsigned *cword;  
   unsigned *rowi;  
   
   rowsize = WORDSIZE(n) * sizeof(unsigned);  
   relend = (unsigned *) ((char *) R + (n * rowsize));  
   
   cword = R;  
   mask = 1;  
   rowi = R;  
   while (rowi < relend)  
     {  
       ccol = cword;  
       rowj = R;  
   
       while (rowj < relend)  
         {  
           if (*ccol & mask)  
             {  
               rp = rowi;  
               rend = (unsigned *) ((char *) rowj + rowsize);  
   
               while (rowj < rend)  
                 *rowj++ |= *rp++;  
             }  
           else  
             {  
               rowj = (unsigned *) ((char *) rowj + rowsize);  
             }  
   
           ccol = (unsigned *) ((char *) ccol + rowsize);  
         }  
   
       mask <<= 1;  
       if (mask == 0)  
         {  
           mask = 1;  
           cword++;  
         }  
37    
38        rowi = (unsigned *) ((char *) rowi + rowsize);    for (i = 0; i < n; ++i)
39      }      for (j = 0; j < n; ++j)
40          if (BITISSET (R (i), j))
41            for (k = 0; k < rowsize; ++k)
42              if (BITISSET (R (i), k))
43                SETBIT (R (j), k);
44  }  }
45    
46    
47  /* Reflexive Transitive Closure.  Same as TC  /*---------------------------------------------------------------.
48     and then set all the bits on the diagonal of R.  */  | Reflexive Transitive Closure.  Same as TC and then set all the |
49    | bits on the diagonal of R.                                     |
50    `---------------------------------------------------------------*/
51    
52  void  void
53  RTC (unsigned *R, int n)  RTC (unsigned *R, int n)
54  {  {
55    int rowsize;    int rowsize = WORDSIZE (n) * sizeof (unsigned);
56    unsigned mask;    int i;
   unsigned *rp;  
   unsigned *relend;  
   
   TC(R, n);  
   
   rowsize = WORDSIZE(n) * sizeof(unsigned);  
   relend = (unsigned *) ((char *) R + n*rowsize);  
   
   mask = 1;  
   rp = R;  
   while (rp < relend)  
     {  
       *rp |= mask;  
   
       mask <<= 1;  
       if (mask == 0)  
         {  
           mask = 1;  
           rp++;  
         }  
57    
58        rp = (unsigned *) ((char *) rp + rowsize);    TC (R, n);
59      }    for (i = 0; i < n; ++i)
60        SETBIT (R (i), i);
61  }  }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.6.2.1

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