]>
Commit | Line | Data |
---|---|---|
f7d4d87a | 1 | /* Generate transitive closure of a matrix, |
d8a0245c | 2 | Copyright 1984, 1989, 2000, 2001, 2002 Free Software Foundation, Inc. |
f7d4d87a | 3 | |
d7913476 | 4 | This file is part of Bison, the GNU Compiler Compiler. |
f7d4d87a | 5 | |
d7913476 AD |
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) | |
9 | any later version. | |
f7d4d87a | 10 | |
d7913476 AD |
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. | |
f7d4d87a | 15 | |
d7913476 AD |
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. */ | |
f7d4d87a DM |
20 | |
21 | ||
f7d4d87a | 22 | #include "system.h" |
74ffbcb6 | 23 | #include "getargs.h" |
914feea9 | 24 | #include "bitsetv.h" |
d7913476 | 25 | #include "warshall.h" |
f7d4d87a | 26 | |
d8a0245c AD |
27 | /*--------------------------------------------------------. |
28 | | Display the MATRIX array of SIZE bitsets of size SIZE. | | |
29 | `--------------------------------------------------------*/ | |
3a7456dd | 30 | |
74ffbcb6 | 31 | static void |
914feea9 | 32 | bitmatrix_print (const char *title, bitsetv matrix) |
74ffbcb6 AD |
33 | { |
34 | size_t i, j; | |
914feea9 | 35 | size_t size = bitset_size (matrix[0]); |
74ffbcb6 AD |
36 | |
37 | /* Title. */ | |
38 | fprintf (stderr, "%s BEGIN\n", title); | |
39 | ||
40 | /* Column numbers. */ | |
41 | fputs (" ", stderr); | |
42 | for (i = 0; i < size; ++i) | |
43 | putc (i / 10 ? '0' + i / 10 : ' ', stderr); | |
44 | putc ('\n', stderr); | |
45 | fputs (" ", stderr); | |
46 | for (i = 0; i < size; ++i) | |
47 | fprintf (stderr, "%d", i % 10); | |
48 | putc ('\n', stderr); | |
49 | ||
50 | /* Bar. */ | |
ed8e1f68 | 51 | fputs (" .", stderr); |
74ffbcb6 AD |
52 | for (i = 0; i < size; ++i) |
53 | putc ('-', stderr); | |
ed8e1f68 | 54 | fputs (".\n", stderr); |
74ffbcb6 AD |
55 | |
56 | /* Contents. */ | |
57 | for (i = 0; i < size; ++i) | |
58 | { | |
59 | fprintf (stderr, "%2d|", i); | |
60 | for (j = 0; j < size; ++j) | |
d8a0245c | 61 | fputs (bitset_test (matrix[i], j) ? "1" : " ", stderr); |
74ffbcb6 AD |
62 | fputs ("|\n", stderr); |
63 | } | |
64 | ||
65 | /* Bar. */ | |
ed8e1f68 | 66 | fputs (" `", stderr); |
74ffbcb6 AD |
67 | for (i = 0; i < size; ++i) |
68 | putc ('-', stderr); | |
ed8e1f68 | 69 | fputs ("'\n", stderr); |
74ffbcb6 AD |
70 | |
71 | /* End title. */ | |
72 | fprintf (stderr, "%s END\n\n", title); | |
73 | } | |
74 | ||
d8a0245c AD |
75 | /*-------------------------------------------------------------------. |
76 | | Given the MATRIX array of N bitsets of size N, modify its contents | | |
77 | | to be the transive closure of what was given. | | |
78 | `-------------------------------------------------------------------*/ | |
f7d4d87a | 79 | |
d2729d44 | 80 | static void |
914feea9 | 81 | TC (bitsetv matrix) |
f7d4d87a | 82 | { |
f9abaa2c | 83 | int i, j; |
3a7456dd | 84 | |
74ffbcb6 | 85 | if (trace_flag) |
914feea9 | 86 | bitmatrix_print ("TC: Input", matrix); |
74ffbcb6 AD |
87 | |
88 | /* R (J, I) && R (I, K) => R (J, K). | |
89 | I *must* be the outter loop. */ | |
90 | ||
914feea9 AD |
91 | for (i = 0; matrix[i]; ++i) |
92 | for (j = 0; matrix[j]; ++j) | |
d8a0245c | 93 | if (bitset_test (matrix[j], i)) |
f9abaa2c | 94 | bitset_or (matrix[j], matrix[j], matrix[i]); |
74ffbcb6 AD |
95 | |
96 | if (trace_flag) | |
914feea9 | 97 | bitmatrix_print ("TC: Output", matrix); |
f7d4d87a DM |
98 | } |
99 | ||
100 | ||
3a7456dd AD |
101 | /*---------------------------------------------------------------. |
102 | | Reflexive Transitive Closure. Same as TC and then set all the | | |
d8a0245c | 103 | | bits on the diagonal of MATRIX. | |
3a7456dd | 104 | `---------------------------------------------------------------*/ |
f7d4d87a DM |
105 | |
106 | void | |
914feea9 | 107 | RTC (bitsetv matrix) |
f7d4d87a | 108 | { |
3a7456dd | 109 | int i; |
f7d4d87a | 110 | |
914feea9 AD |
111 | TC (matrix); |
112 | for (i = 0; matrix[i]; ++i) | |
d8a0245c | 113 | bitset_set (matrix[i], i); |
f7d4d87a | 114 | } |