]>
git.saurik.com Git - bison.git/blob - src/warshall.c
c962bc7fdb6577046ca037a48519ea9a25d1c0aa
1 /* Generate transitive closure of a matrix,
2 Copyright 1984, 1989, 2000, 2001, 2002 Free Software Foundation, Inc.
4 This file is part of Bison, the GNU Compiler Compiler.
6 Bison is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 Bison is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Bison; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
27 /*--------------------------------------------------------.
28 | Display the MATRIX array of SIZE bitsets of size SIZE. |
29 `--------------------------------------------------------*/
32 bitmatrix_print (const char *title
, bitset
*matrix
, size_t size
)
37 fprintf (stderr
, "%s BEGIN\n", title
);
41 for (i
= 0; i
< size
; ++i
)
42 putc (i
/ 10 ? '0' + i
/ 10 : ' ', stderr
);
45 for (i
= 0; i
< size
; ++i
)
46 fprintf (stderr
, "%d", i
% 10);
51 for (i
= 0; i
< size
; ++i
)
53 fputs (".\n", stderr
);
56 for (i
= 0; i
< size
; ++i
)
58 fprintf (stderr
, "%2d|", i
);
59 for (j
= 0; j
< size
; ++j
)
60 fputs (bitset_test (matrix
[i
], j
) ? "1" : " ", stderr
);
61 fputs ("|\n", stderr
);
66 for (i
= 0; i
< size
; ++i
)
68 fputs ("'\n", stderr
);
71 fprintf (stderr
, "%s END\n\n", title
);
74 /*-------------------------------------------------------------------.
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 `-------------------------------------------------------------------*/
80 TC (bitset
*matrix
, int n
)
85 bitmatrix_print ("TC: Input", matrix
, n
);
87 /* R (J, I) && R (I, K) => R (J, K).
88 I *must* be the outter loop. */
90 for (i
= 0; i
< n
; ++i
)
91 for (j
= 0; j
< n
; ++j
)
92 if (bitset_test (matrix
[j
], i
))
93 bitset_or (matrix
[j
], matrix
[j
], matrix
[i
]);
96 bitmatrix_print ("TC: Output", matrix
, n
);
100 /*---------------------------------------------------------------.
101 | Reflexive Transitive Closure. Same as TC and then set all the |
102 | bits on the diagonal of MATRIX. |
103 `---------------------------------------------------------------*/
106 RTC (bitset
*matrix
, int n
)
111 for (i
= 0; i
< n
; ++i
)
112 bitset_set (matrix
[i
], i
);