Berkeley YACC  1993-03-03
Berkeley's version of Yet Another Compiler Compiler
 All Data Structures Files Functions Variables Typedefs Macros Groups
warshall.c File Reference
#include "defs.h"
+ Include dependency graph for warshall.c:

Go to the source code of this file.

Functions

 transitive_closure (unsigned *R, int n)
 
 reflexive_transitive_closure (unsigned *R, int n)
 

Function Documentation

reflexive_transitive_closure ( unsigned *  R,
int  n 
)

Computes the transitive closure of a relation in-place.

Let \( \mathrm{R} \) be an \( \mathrm{n} \times \mathrm{n} \) matrix of bits expressing a relation between n elements, such that \( \mathrm{R}_{i,j} \) is set if and only if the i-th elements is in relation with the j-th one.

Then this function computes the reflexive and transitive closure of such relation and stores it in-place, using Warshall's algorithm. Its complexity is \( O\left( n^3 \right) \), dominated by the complexity of transitive_closure().

Internally, this function just calls transitive_closure() and then sets all elements on the matrix diagonal to make the relation reflexive.

Definition at line 79 of file warshall.c.

References BITS_PER_WORD, R, transitive_closure(), and WORDSIZE.

Referenced by set_EFF().

82 {
83  register int rowsize;
84  register unsigned i;
85  register unsigned *rp;
86  register unsigned *relend;
87 
89 
90  rowsize = WORDSIZE(n);
91  relend = R + n*rowsize;
92 
93  i = 0;
94  rp = R;
95  while (rp < relend)
96  {
97  *rp |= (1 << i);
98  if (++i >= BITS_PER_WORD)
99  {
100  i = 0;
101  rp++;
102  }
103 
104  rp += rowsize;
105  }
106 }
transitive_closure(unsigned *R, int n)
Definition: warshall.c:13
#define BITS_PER_WORD
Definition: defs.h:25
#define WORDSIZE(n)
Definition: defs.h:26
static short ** R
Definition: lalr.c:31

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

transitive_closure ( unsigned *  R,
int  n 
)

Computes the transitive closure of a relation in-place.

Let \( \mathrm{R} \) be an \( \mathrm{n} \times \mathrm{n} \) matrix of bits expressing a relation between n elements, such that \( \mathrm{R}_{i,j} \) is set if and only if the i-th elements is in relation with the j-th one.

Then this function computes the transitive closure of such relation and stores it in-place, using Warshall's algorithm. Its complexity is \( O\left( n^3 \right) \).

Definition at line 13 of file warshall.c.

References BITS_PER_WORD, R, and WORDSIZE.

Referenced by reflexive_transitive_closure().

16 {
17  register int rowsize;
18  register unsigned i;
19  register unsigned *rowj;
20  register unsigned *rp;
21  register unsigned *rend;
22  register unsigned *ccol;
23  register unsigned *relend;
24  register unsigned *cword;
25  register unsigned *rowi;
26 
27  rowsize = WORDSIZE(n);
28  relend = R + n*rowsize;
29 
30  cword = R;
31  i = 0;
32  rowi = R;
33  while (rowi < relend)
34  {
35  ccol = cword;
36  rowj = R;
37 
38  while (rowj < relend)
39  {
40  if (*ccol & (1 << i))
41  {
42  rp = rowi;
43  rend = rowj + rowsize;
44  while (rowj < rend)
45  *rowj++ |= *rp++;
46  }
47  else
48  {
49  rowj += rowsize;
50  }
51 
52  ccol += rowsize;
53  }
54 
55  if (++i >= BITS_PER_WORD)
56  {
57  i = 0;
58  cword++;
59  }
60 
61  rowi += rowsize;
62  }
63 }
#define BITS_PER_WORD
Definition: defs.h:25
#define WORDSIZE(n)
Definition: defs.h:26
static short ** R
Definition: lalr.c:31

+ Here is the caller graph for this function: