annotate gcc/sbitmap.h @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Simple bitmaps.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 1999-2020 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 #ifndef GCC_SBITMAP_H
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #define GCC_SBITMAP_H
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
111
kono
parents: 67
diff changeset
23 /* Implementation of sets using simple bitmap vectors.
kono
parents: 67
diff changeset
24
kono
parents: 67
diff changeset
25 This set representation is suitable for non-sparse sets with a known
kono
parents: 67
diff changeset
26 (a priori) universe. The set is represented as a simple array of the
kono
parents: 67
diff changeset
27 host's fastest unsigned integer. For a given member I in the set:
kono
parents: 67
diff changeset
28 - the element for I will be at sbitmap[I / (bits per element)]
kono
parents: 67
diff changeset
29 - the position for I within element is I % (bits per element)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
111
kono
parents: 67
diff changeset
31 This representation is very space-efficient for large non-sparse sets
kono
parents: 67
diff changeset
32 with random access patterns.
kono
parents: 67
diff changeset
33
kono
parents: 67
diff changeset
34 The following operations can be performed in O(1) time:
kono
parents: 67
diff changeset
35
kono
parents: 67
diff changeset
36 * set_size : SBITMAP_SIZE
kono
parents: 67
diff changeset
37 * member_p : bitmap_bit_p
kono
parents: 67
diff changeset
38 * add_member : bitmap_set_bit
kono
parents: 67
diff changeset
39 * remove_member : bitmap_clear_bit
kono
parents: 67
diff changeset
40
kono
parents: 67
diff changeset
41 Most other operations on this set representation are O(U) where U is
kono
parents: 67
diff changeset
42 the size of the set universe:
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
111
kono
parents: 67
diff changeset
44 * clear : bitmap_clear
kono
parents: 67
diff changeset
45 * choose_one : bitmap_first_set_bit /
kono
parents: 67
diff changeset
46 bitmap_last_set_bit
kono
parents: 67
diff changeset
47 * forall : EXECUTE_IF_SET_IN_BITMAP
kono
parents: 67
diff changeset
48 * set_copy : bitmap_copy
kono
parents: 67
diff changeset
49 * set_intersection : bitmap_and
kono
parents: 67
diff changeset
50 * set_union : bitmap_ior
kono
parents: 67
diff changeset
51 * set_difference : bitmap_and_compl
kono
parents: 67
diff changeset
52 * set_disjuction : (not implemented)
kono
parents: 67
diff changeset
53 * set_compare : bitmap_equal_p
kono
parents: 67
diff changeset
54 * bit_in_range_p : bitmap_bit_in_range_p
kono
parents: 67
diff changeset
55
kono
parents: 67
diff changeset
56 Some operations on 3 sets that occur frequently in data flow problems
kono
parents: 67
diff changeset
57 are also implemented:
kono
parents: 67
diff changeset
58
kono
parents: 67
diff changeset
59 * A | (B & C) : bitmap_or_and
kono
parents: 67
diff changeset
60 * A | (B & ~C) : bitmap_ior_and_compl
kono
parents: 67
diff changeset
61 * A & (B | C) : bitmap_and_or
kono
parents: 67
diff changeset
62
kono
parents: 67
diff changeset
63 Most of the set functions have two variants: One that returns non-zero
kono
parents: 67
diff changeset
64 if members were added or removed from the target set, and one that just
kono
parents: 67
diff changeset
65 performs the operation without feedback. The former operations are a
kono
parents: 67
diff changeset
66 bit more expensive but the result can often be used to avoid iterations
kono
parents: 67
diff changeset
67 on other sets.
kono
parents: 67
diff changeset
68
kono
parents: 67
diff changeset
69 Allocating a bitmap is done with sbitmap_alloc, and resizing is
kono
parents: 67
diff changeset
70 performed with sbitmap_resize.
kono
parents: 67
diff changeset
71
kono
parents: 67
diff changeset
72 The storage requirements for simple bitmap sets is O(U) where U is the
kono
parents: 67
diff changeset
73 size of the set universe (colloquially the number of bits in the bitmap).
kono
parents: 67
diff changeset
74
kono
parents: 67
diff changeset
75 This set representation works well for relatively small data flow problems
kono
parents: 67
diff changeset
76 (there are special routines for that, see sbitmap_vector_*). The set
kono
parents: 67
diff changeset
77 operations can be vectorized and there is almost no computating overhead,
kono
parents: 67
diff changeset
78 so that even sparse simple bitmap sets outperform dedicated sparse set
kono
parents: 67
diff changeset
79 representations like linked-list bitmaps. For larger problems, the size
kono
parents: 67
diff changeset
80 overhead of simple bitmap sets gets too high and other set representations
kono
parents: 67
diff changeset
81 have to be used. */
kono
parents: 67
diff changeset
82
kono
parents: 67
diff changeset
83 #define SBITMAP_ELT_BITS (HOST_BITS_PER_WIDEST_FAST_INT * 1u)
kono
parents: 67
diff changeset
84 #define SBITMAP_ELT_TYPE unsigned HOST_WIDEST_FAST_INT
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
86 struct simple_bitmap_def
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 unsigned int n_bits; /* Number of bits. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 unsigned int size; /* Size in elements. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 SBITMAP_ELT_TYPE elms[1]; /* The elements. */
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
91 };
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 /* Return the set size needed for N elements. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 #define SBITMAP_SET_SIZE(N) (((N) + SBITMAP_ELT_BITS - 1) / SBITMAP_ELT_BITS)
111
kono
parents: 67
diff changeset
95
kono
parents: 67
diff changeset
96 /* Return the number of bits in BITMAP. */
kono
parents: 67
diff changeset
97 #define SBITMAP_SIZE(BITMAP) ((BITMAP)->n_bits)
kono
parents: 67
diff changeset
98
kono
parents: 67
diff changeset
99 /* Verify that access at INDEX in bitmap MAP is valid. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100
111
kono
parents: 67
diff changeset
101 static inline void
kono
parents: 67
diff changeset
102 bitmap_check_index (const_sbitmap map, int index)
kono
parents: 67
diff changeset
103 {
kono
parents: 67
diff changeset
104 gcc_checking_assert (index >= 0);
kono
parents: 67
diff changeset
105 gcc_checking_assert ((unsigned int)index < map->n_bits);
kono
parents: 67
diff changeset
106 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
111
kono
parents: 67
diff changeset
108 /* Verify that bitmaps A and B have same size. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 static inline void
111
kono
parents: 67
diff changeset
111 bitmap_check_sizes (const_sbitmap a, const_sbitmap b)
kono
parents: 67
diff changeset
112 {
kono
parents: 67
diff changeset
113 gcc_checking_assert (a->n_bits == b->n_bits);
kono
parents: 67
diff changeset
114 }
kono
parents: 67
diff changeset
115
kono
parents: 67
diff changeset
116 /* Test if bit number bitno in the bitmap is set. */
kono
parents: 67
diff changeset
117 static inline SBITMAP_ELT_TYPE
kono
parents: 67
diff changeset
118 bitmap_bit_p (const_sbitmap map, int bitno)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 {
111
kono
parents: 67
diff changeset
120 bitmap_check_index (map, bitno);
kono
parents: 67
diff changeset
121
kono
parents: 67
diff changeset
122 size_t i = bitno / SBITMAP_ELT_BITS;
kono
parents: 67
diff changeset
123 unsigned int s = bitno % SBITMAP_ELT_BITS;
kono
parents: 67
diff changeset
124 return (map->elms[i] >> s) & (SBITMAP_ELT_TYPE) 1;
kono
parents: 67
diff changeset
125 }
kono
parents: 67
diff changeset
126
kono
parents: 67
diff changeset
127 /* Set bit number BITNO in the sbitmap MAP. */
kono
parents: 67
diff changeset
128
kono
parents: 67
diff changeset
129 static inline void
kono
parents: 67
diff changeset
130 bitmap_set_bit (sbitmap map, int bitno)
kono
parents: 67
diff changeset
131 {
kono
parents: 67
diff changeset
132 bitmap_check_index (map, bitno);
kono
parents: 67
diff changeset
133
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 map->elms[bitno / SBITMAP_ELT_BITS]
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 |= (SBITMAP_ELT_TYPE) 1 << (bitno) % SBITMAP_ELT_BITS;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137
111
kono
parents: 67
diff changeset
138 /* Reset bit number BITNO in the sbitmap MAP. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 static inline void
111
kono
parents: 67
diff changeset
141 bitmap_clear_bit (sbitmap map, int bitno)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 {
111
kono
parents: 67
diff changeset
143 bitmap_check_index (map, bitno);
kono
parents: 67
diff changeset
144
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 map->elms[bitno / SBITMAP_ELT_BITS]
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 &= ~((SBITMAP_ELT_TYPE) 1 << (bitno) % SBITMAP_ELT_BITS);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 /* The iterator for sbitmap. */
111
kono
parents: 67
diff changeset
150 struct sbitmap_iterator {
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 /* The pointer to the first word of the bitmap. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 const SBITMAP_ELT_TYPE *ptr;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 /* The size of the bitmap. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 unsigned int size;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 /* The current word index. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 unsigned int word_num;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 /* The current bit index (not modulo SBITMAP_ELT_BITS). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 unsigned int bit_num;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 /* The words currently visited. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 SBITMAP_ELT_TYPE word;
111
kono
parents: 67
diff changeset
165 };
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 /* Initialize the iterator I with sbitmap BMP and the initial index
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 MIN. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 static inline void
111
kono
parents: 67
diff changeset
171 bmp_iter_set_init (sbitmap_iterator *i, const_sbitmap bmp,
kono
parents: 67
diff changeset
172 unsigned int min, unsigned *bit_no ATTRIBUTE_UNUSED)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 i->word_num = min / (unsigned int) SBITMAP_ELT_BITS;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 i->bit_num = min;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 i->size = bmp->size;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 i->ptr = bmp->elms;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 if (i->word_num >= i->size)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 i->word = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 i->word = (i->ptr[i->word_num]
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 >> (i->bit_num % (unsigned int) SBITMAP_ELT_BITS));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 /* Return true if we have more bits to visit, in which case *N is set
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 to the index of the bit to be visited. Otherwise, return
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 false. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 static inline bool
111
kono
parents: 67
diff changeset
191 bmp_iter_set (sbitmap_iterator *i, unsigned int *n)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 /* Skip words that are zeros. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 for (; i->word == 0; i->word = i->ptr[i->word_num])
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 i->word_num++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 /* If we have reached the end, break. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 if (i->word_num >= i->size)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 i->bit_num = i->word_num * SBITMAP_ELT_BITS;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 /* Skip bits that are zero. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 for (; (i->word & 1) == 0; i->word >>= 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 i->bit_num++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 *n = i->bit_num;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 /* Advance to the next bit. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 static inline void
111
kono
parents: 67
diff changeset
217 bmp_iter_next (sbitmap_iterator *i, unsigned *bit_no ATTRIBUTE_UNUSED)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 i->word >>= 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 i->bit_num++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 /* Loop over all elements of SBITMAP, starting with MIN. In each
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 iteration, N is set to the index of the bit being visited. ITER is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 an instance of sbitmap_iterator used to iterate the bitmap. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226
111
kono
parents: 67
diff changeset
227 #ifndef EXECUTE_IF_SET_IN_BITMAP
kono
parents: 67
diff changeset
228 /* See bitmap.h for the other definition of EXECUTE_IF_SET_IN_BITMAP. */
kono
parents: 67
diff changeset
229 #define EXECUTE_IF_SET_IN_BITMAP(BITMAP, MIN, BITNUM, ITER) \
kono
parents: 67
diff changeset
230 for (bmp_iter_set_init (&(ITER), (BITMAP), (MIN), &(BITNUM)); \
kono
parents: 67
diff changeset
231 bmp_iter_set (&(ITER), &(BITNUM)); \
kono
parents: 67
diff changeset
232 bmp_iter_next (&(ITER), &(BITNUM)))
kono
parents: 67
diff changeset
233 #endif
kono
parents: 67
diff changeset
234
kono
parents: 67
diff changeset
235 inline void sbitmap_free (sbitmap map)
kono
parents: 67
diff changeset
236 {
kono
parents: 67
diff changeset
237 free (map);
kono
parents: 67
diff changeset
238 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
239
111
kono
parents: 67
diff changeset
240 inline void sbitmap_vector_free (sbitmap * vec)
kono
parents: 67
diff changeset
241 {
kono
parents: 67
diff changeset
242 free (vec);
kono
parents: 67
diff changeset
243 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244
111
kono
parents: 67
diff changeset
245 extern void dump_bitmap (FILE *, const_sbitmap);
kono
parents: 67
diff changeset
246 extern void debug_raw (const simple_bitmap_def &ref);
kono
parents: 67
diff changeset
247 extern void debug_raw (const simple_bitmap_def *ptr);
kono
parents: 67
diff changeset
248 extern void dump_bitmap_file (FILE *, const_sbitmap);
kono
parents: 67
diff changeset
249 extern void debug (const simple_bitmap_def &ref);
kono
parents: 67
diff changeset
250 extern void debug (const simple_bitmap_def *ptr);
kono
parents: 67
diff changeset
251 extern void dump_bitmap_vector (FILE *, const char *, const char *, sbitmap *,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 int);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 extern sbitmap sbitmap_alloc (unsigned int);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 extern sbitmap *sbitmap_vector_alloc (unsigned int, unsigned int);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 extern sbitmap sbitmap_resize (sbitmap, unsigned int, int);
111
kono
parents: 67
diff changeset
256 extern void bitmap_copy (sbitmap, const_sbitmap);
kono
parents: 67
diff changeset
257 extern int bitmap_equal_p (const_sbitmap, const_sbitmap);
kono
parents: 67
diff changeset
258 extern unsigned int bitmap_count_bits (const_sbitmap);
kono
parents: 67
diff changeset
259 extern bool bitmap_empty_p (const_sbitmap);
kono
parents: 67
diff changeset
260 extern void bitmap_clear (sbitmap);
kono
parents: 67
diff changeset
261 extern void bitmap_clear_range (sbitmap, unsigned, unsigned);
kono
parents: 67
diff changeset
262 extern void bitmap_set_range (sbitmap, unsigned, unsigned);
kono
parents: 67
diff changeset
263 extern void bitmap_ones (sbitmap);
kono
parents: 67
diff changeset
264 extern void bitmap_vector_clear (sbitmap *, unsigned int);
kono
parents: 67
diff changeset
265 extern void bitmap_vector_ones (sbitmap *, unsigned int);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
266
111
kono
parents: 67
diff changeset
267 extern bool bitmap_ior_and_compl (sbitmap, const_sbitmap,
kono
parents: 67
diff changeset
268 const_sbitmap, const_sbitmap);
kono
parents: 67
diff changeset
269 extern void bitmap_and_compl (sbitmap, const_sbitmap, const_sbitmap);
kono
parents: 67
diff changeset
270 extern void bitmap_not (sbitmap, const_sbitmap);
kono
parents: 67
diff changeset
271 extern bool bitmap_or_and (sbitmap, const_sbitmap,
kono
parents: 67
diff changeset
272 const_sbitmap, const_sbitmap);
kono
parents: 67
diff changeset
273 extern bool bitmap_and_or (sbitmap, const_sbitmap,
kono
parents: 67
diff changeset
274 const_sbitmap, const_sbitmap);
kono
parents: 67
diff changeset
275 extern bool bitmap_intersect_p (const_sbitmap, const_sbitmap);
kono
parents: 67
diff changeset
276 extern bool bitmap_and (sbitmap, const_sbitmap, const_sbitmap);
kono
parents: 67
diff changeset
277 extern bool bitmap_ior (sbitmap, const_sbitmap, const_sbitmap);
kono
parents: 67
diff changeset
278 extern bool bitmap_xor (sbitmap, const_sbitmap, const_sbitmap);
kono
parents: 67
diff changeset
279 extern bool bitmap_subset_p (const_sbitmap, const_sbitmap);
kono
parents: 67
diff changeset
280 extern bool bitmap_bit_in_range_p (const_sbitmap, unsigned int, unsigned int);
kono
parents: 67
diff changeset
281
kono
parents: 67
diff changeset
282 extern int bitmap_first_set_bit (const_sbitmap);
kono
parents: 67
diff changeset
283 extern int bitmap_last_set_bit (const_sbitmap);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284
111
kono
parents: 67
diff changeset
285 extern void debug_bitmap (const_sbitmap);
kono
parents: 67
diff changeset
286 extern sbitmap sbitmap_realloc (sbitmap, unsigned int);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287
111
kono
parents: 67
diff changeset
288 /* a class that ties the lifetime of a sbitmap to its scope. */
kono
parents: 67
diff changeset
289 class auto_sbitmap
kono
parents: 67
diff changeset
290 {
kono
parents: 67
diff changeset
291 public:
kono
parents: 67
diff changeset
292 explicit auto_sbitmap (unsigned int size) :
kono
parents: 67
diff changeset
293 m_bitmap (sbitmap_alloc (size)) {}
kono
parents: 67
diff changeset
294 ~auto_sbitmap () { sbitmap_free (m_bitmap); }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295
111
kono
parents: 67
diff changeset
296 /* Allow calling sbitmap functions on our bitmap. */
kono
parents: 67
diff changeset
297 operator sbitmap () { return m_bitmap; }
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
298 operator const_sbitmap () const { return m_bitmap; }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299
111
kono
parents: 67
diff changeset
300 private:
kono
parents: 67
diff changeset
301 /* Prevent making a copy that refers to our sbitmap. */
kono
parents: 67
diff changeset
302 auto_sbitmap (const auto_sbitmap &);
kono
parents: 67
diff changeset
303 auto_sbitmap &operator = (const auto_sbitmap &);
kono
parents: 67
diff changeset
304 #if __cplusplus >= 201103L
kono
parents: 67
diff changeset
305 auto_sbitmap (auto_sbitmap &&);
kono
parents: 67
diff changeset
306 auto_sbitmap &operator = (auto_sbitmap &&);
kono
parents: 67
diff changeset
307 #endif
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
308
111
kono
parents: 67
diff changeset
309 /* The bitmap we are managing. */
kono
parents: 67
diff changeset
310 sbitmap m_bitmap;
kono
parents: 67
diff changeset
311 };
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
312
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 #endif /* ! GCC_SBITMAP_H */