]> git.saurik.com Git - bison.git/blame - src/warshall.c
Various anti-`extern in *.c' changes.
[bison.git] / src / warshall.c
CommitLineData
f7d4d87a
DM
1/* Generate transitive closure of a matrix,
2 Copyright (C) 1984, 1989 Free Software Foundation, Inc.
3
4This file is part of Bison, the GNU Compiler Compiler.
5
6Bison is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11Bison is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with Bison; see the file COPYING. If not, write to
c49a8e71
JT
18the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
f7d4d87a
DM
20
21
f7d4d87a 22#include "system.h"
f7d4d87a 23
d2729d44
JT
24void RTC PARAMS((unsigned *, int));
25
f7d4d87a
DM
26
27/* given n by n matrix of bits R, modify its contents
28 to be the transive closure of what was given. */
29
d2729d44
JT
30static void
31TC (unsigned *R, int n)
f7d4d87a
DM
32{
33 register int rowsize;
34 register unsigned mask;
35 register unsigned *rowj;
36 register unsigned *rp;
37 register unsigned *rend;
38 register unsigned *ccol;
39
40 unsigned *relend;
41 unsigned *cword;
42 unsigned *rowi;
43
44 rowsize = WORDSIZE(n) * sizeof(unsigned);
45 relend = (unsigned *) ((char *) R + (n * rowsize));
46
47 cword = R;
48 mask = 1;
49 rowi = R;
50 while (rowi < relend)
51 {
52 ccol = cword;
53 rowj = R;
54
55 while (rowj < relend)
56 {
57 if (*ccol & mask)
58 {
59 rp = rowi;
60 rend = (unsigned *) ((char *) rowj + rowsize);
61
62 while (rowj < rend)
63 *rowj++ |= *rp++;
64 }
65 else
66 {
67 rowj = (unsigned *) ((char *) rowj + rowsize);
68 }
69
70 ccol = (unsigned *) ((char *) ccol + rowsize);
71 }
72
73 mask <<= 1;
74 if (mask == 0)
75 {
76 mask = 1;
77 cword++;
78 }
79
80 rowi = (unsigned *) ((char *) rowi + rowsize);
81 }
82}
83
84
85/* Reflexive Transitive Closure. Same as TC
86 and then set all the bits on the diagonal of R. */
87
88void
d2729d44 89RTC (unsigned *R, int n)
f7d4d87a
DM
90{
91 register int rowsize;
92 register unsigned mask;
93 register unsigned *rp;
94 register unsigned *relend;
95
96 TC(R, n);
97
98 rowsize = WORDSIZE(n) * sizeof(unsigned);
99 relend = (unsigned *) ((char *) R + n*rowsize);
100
101 mask = 1;
102 rp = R;
103 while (rp < relend)
104 {
105 *rp |= mask;
106
107 mask <<= 1;
108 if (mask == 0)
109 {
110 mask = 1;
111 rp++;
112 }
113
114 rp = (unsigned *) ((char *) rp + rowsize);
115 }
116}