]>
git.saurik.com Git - bison.git/blob - src/warshall.c
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
, bitsetv matrix
)
35 size_t size
= bitset_size (matrix
[0]);
38 fprintf (stderr
, "%s BEGIN\n", title
);
42 for (i
= 0; i
< size
; ++i
)
43 putc (i
/ 10 ? '0' + i
/ 10 : ' ', stderr
);
46 for (i
= 0; i
< size
; ++i
)
47 fprintf (stderr
, "%d", i
% 10);
52 for (i
= 0; i
< size
; ++i
)
54 fputs (".\n", stderr
);
57 for (i
= 0; i
< size
; ++i
)
59 fprintf (stderr
, "%2d|", i
);
60 for (j
= 0; j
< size
; ++j
)
61 fputs (bitset_test (matrix
[i
], j
) ? "1" : " ", stderr
);
62 fputs ("|\n", stderr
);
67 for (i
= 0; i
< size
; ++i
)
69 fputs ("'\n", stderr
);
72 fprintf (stderr
, "%s END\n\n", title
);
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 `-------------------------------------------------------------------*/
86 bitmatrix_print ("TC: Input", matrix
);
88 /* R (J, I) && R (I, K) => R (J, K).
89 I *must* be the outter loop. */
91 for (i
= 0; matrix
[i
]; ++i
)
92 for (j
= 0; matrix
[j
]; ++j
)
93 if (bitset_test (matrix
[j
], i
))
94 bitset_or (matrix
[j
], matrix
[j
], matrix
[i
]);
97 bitmatrix_print ("TC: Output", matrix
);
101 /*---------------------------------------------------------------.
102 | Reflexive Transitive Closure. Same as TC and then set all the |
103 | bits on the diagonal of MATRIX. |
104 `---------------------------------------------------------------*/
112 for (i
= 0; matrix
[i
]; ++i
)
113 bitset_set (matrix
[i
], i
);