]> git.saurik.com Git - bison.git/blame - src/warshall.c
* src/lalr.h, src/lalr.c (tokensetsize): Remove, unused.
[bison.git] / src / warshall.c
CommitLineData
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"
d8a0245c 24#include "bitset.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 31static void
d8a0245c 32bitmatrix_print (const char *title, bitset *matrix, size_t size)
74ffbcb6
AD
33{
34 size_t i, j;
74ffbcb6
AD
35
36 /* Title. */
37 fprintf (stderr, "%s BEGIN\n", title);
38
39 /* Column numbers. */
40 fputs (" ", stderr);
41 for (i = 0; i < size; ++i)
42 putc (i / 10 ? '0' + i / 10 : ' ', stderr);
43 putc ('\n', stderr);
44 fputs (" ", stderr);
45 for (i = 0; i < size; ++i)
46 fprintf (stderr, "%d", i % 10);
47 putc ('\n', stderr);
48
49 /* Bar. */
ed8e1f68 50 fputs (" .", stderr);
74ffbcb6
AD
51 for (i = 0; i < size; ++i)
52 putc ('-', stderr);
ed8e1f68 53 fputs (".\n", stderr);
74ffbcb6
AD
54
55 /* Contents. */
56 for (i = 0; i < size; ++i)
57 {
58 fprintf (stderr, "%2d|", i);
59 for (j = 0; j < size; ++j)
d8a0245c 60 fputs (bitset_test (matrix[i], j) ? "1" : " ", stderr);
74ffbcb6
AD
61 fputs ("|\n", stderr);
62 }
63
64 /* Bar. */
ed8e1f68 65 fputs (" `", stderr);
74ffbcb6
AD
66 for (i = 0; i < size; ++i)
67 putc ('-', stderr);
ed8e1f68 68 fputs ("'\n", stderr);
74ffbcb6
AD
69
70 /* End title. */
71 fprintf (stderr, "%s END\n\n", title);
72}
73
d8a0245c
AD
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`-------------------------------------------------------------------*/
f7d4d87a 78
d2729d44 79static void
d8a0245c 80TC (bitset *matrix, int n)
f7d4d87a 81{
3a7456dd
AD
82 int i, j, k;
83
74ffbcb6 84 if (trace_flag)
d8a0245c 85 bitmatrix_print ("TC: Input", matrix, n);
74ffbcb6
AD
86
87 /* R (J, I) && R (I, K) => R (J, K).
88 I *must* be the outter loop. */
89
3a7456dd
AD
90 for (i = 0; i < n; ++i)
91 for (j = 0; j < n; ++j)
d8a0245c 92 if (bitset_test (matrix[j], i))
74ffbcb6 93 for (k = 0; k < n; ++k)
d8a0245c
AD
94 if (bitset_test (matrix[i], k))
95 bitset_set (matrix[j], k);
74ffbcb6
AD
96
97 if (trace_flag)
d8a0245c 98 bitmatrix_print ("TC: Output", matrix, n);
f7d4d87a
DM
99}
100
101
3a7456dd
AD
102/*---------------------------------------------------------------.
103| Reflexive Transitive Closure. Same as TC and then set all the |
d8a0245c 104| bits on the diagonal of MATRIX. |
3a7456dd 105`---------------------------------------------------------------*/
f7d4d87a
DM
106
107void
d8a0245c 108RTC (bitset *matrix, int n)
f7d4d87a 109{
3a7456dd 110 int i;
f7d4d87a 111
d8a0245c 112 TC (matrix, n);
3a7456dd 113 for (i = 0; i < n; ++i)
d8a0245c 114 bitset_set (matrix[i], i);
f7d4d87a 115}