]>
git.saurik.com Git - bison.git/blob - lib/bitsetv.c
2 Copyright (C) 2001, 2002 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
29 /* Create a vector of N_VECS bitsets, each of N_BITS, and of
32 bitsetv_alloc (n_vecs
, n_bits
, type
)
35 enum bitset_type type
;
42 /* Determine number of bytes for each set. */
43 bytes
= bitset_bytes (type
, n_bits
);
45 /* If size calculation overflows, memory is exhausted. */
46 if (BITSET_SIZE_MAX
/ (sizeof (bitset
) + bytes
) <= n_vecs
)
49 /* Allocate vector table at head of bitset array. */
50 vector_bytes
= (n_vecs
+ 1) * sizeof (bitset
);
51 bsetv
= (bitset
*) xcalloc (1, vector_bytes
+ bytes
* n_vecs
);
53 for (i
= 0; i
< n_vecs
; i
++)
55 bsetv
[i
] = (bitset
) ((char *) bsetv
+ vector_bytes
+ i
* bytes
);
57 bitset_init (bsetv
[i
], n_bits
, type
);
60 /* Null terminate table. */
66 /* Create a vector of N_VECS bitsets, each of N_BITS, and with
67 attribute hints specified by ATTR. */
69 bitsetv_create (n_vecs
, n_bits
, attr
)
74 enum bitset_type type
;
76 type
= bitset_type_choose (n_bits
, attr
);
77 return bitsetv_alloc (n_vecs
, n_bits
, type
);
81 /* Free bitset vector BSETV. */
88 for (i
= 0; bsetv
[i
]; i
++)
89 BITSET_FREE_ (bsetv
[i
]);
94 /* Zero a vector of bitsets. */
97 struct bitset_struct
**bsetv
;
101 for (i
= 0; bsetv
[i
]; i
++)
102 bitset_zero (bsetv
[i
]);
106 /* Set a vector of bitsets to ones. */
113 for (i
= 0; bsetv
[i
]; i
++)
114 bitset_ones (bsetv
[i
]);
118 /* Given a vector BSETV of N bitsets of size N, modify its contents to
119 be the transitive closure of what was given. */
121 bitsetv_transitive_closure (bsetv
)
127 for (i
= 0; bsetv
[i
]; i
++)
128 for (j
= 0; bsetv
[j
]; j
++)
129 if (bitset_test (bsetv
[j
], i
))
130 bitset_or (bsetv
[j
], bsetv
[j
], bsetv
[i
]);
134 /* Given a vector BSETV of N bitsets of size N, modify its contents to
135 be the reflexive transitive closure of what was given. This is
136 the same as transitive closure but with all bits on the diagonal
137 of the bit matrix set. */
139 bitsetv_reflexive_transitive_closure (bitsetv bsetv
)
143 bitsetv_transitive_closure (bsetv
);
144 for (i
= 0; bsetv
[i
]; i
++)
145 bitset_set (bsetv
[i
], i
);
149 /* Dump the contents of a bitset vector BSETV with N_VECS elements to
152 bitsetv_dump (file
, title
, subtitle
, bsetv
)
154 const char *title
, *subtitle
;
159 fprintf (file
, "%s\n", title
);
160 for (i
= 0; bsetv
[i
]; i
++)
162 fprintf (file
, "%s %lu\n", subtitle
, (unsigned long) i
);
163 bitset_dump (file
, bsetv
[i
]);
166 fprintf (file
, "\n");
171 debug_bitsetv (bsetv
)
176 for (i
= 0; bsetv
[i
]; i
++)
178 fprintf (stderr
, "%lu: ", (unsigned long) i
);
179 debug_bitset (bsetv
[i
]);
182 fprintf (stderr
, "\n");