1 /* Functions to support expandable bitsets.
2 Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3 Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 /* This file implements expandable bitsets. These bitsets can be of
29 arbitrary length and are more efficient than arrays of bits for
32 Empty elements are represented by a NULL pointer in the table of
33 element pointers. An alternative is to point to a special zero
34 element. Similarly, we could represent an all 1's element with
35 another special ones element pointer.
37 Bitsets are commonly empty so we need to ensure that this special
38 case is fast. A zero bitset is indicated when cdata is 0. This is
39 conservative since cdata may be non zero and the bitset may still
42 The bitset cache can be disabled either by setting cindex to
43 BITSET_WINDEX_MAX or by setting csize to 0. Here
44 we use the former approach since cindex needs to be updated whenever
49 /* Number of words to use for each element. */
50 #define EBITSET_ELT_WORDS 2
52 /* Number of bits stored in each element. */
53 #define EBITSET_ELT_BITS \
54 ((unsigned) (EBITSET_ELT_WORDS * BITSET_WORD_BITS))
56 /* Ebitset element. We use an array of bits. */
57 typedef struct ebitset_elt_struct
61 bitset_word words
[EBITSET_ELT_WORDS
]; /* Bits that are set. */
62 struct ebitset_elt_struct
*next
;
69 typedef ebitset_elt
*ebitset_elts
;
72 /* Number of elements to initially allocate. */
74 #ifndef EBITSET_INITIAL_SIZE
75 #define EBITSET_INITIAL_SIZE 2
78 /* Minimum number of elements to grow table. */
80 #ifndef EBITSET_GROW_SIZE
81 #define EBITSET_GROW_SIZE 4
84 enum ebitset_find_mode
85 { EBITSET_FIND
, EBITSET_CREATE
, EBITSET_SUBST
};
87 static ebitset_elt ebitset_zero_elts
[1]; /* Elements of all zero bits. */
89 /* Obstack to allocate bitset elements from. */
90 static struct obstack ebitset_obstack
;
91 static bool ebitset_obstack_init
= false;
92 static ebitset_elt
*ebitset_free_list
; /* Free list of bitset elements. */
94 #define EBITSET_ELTS(BSET) ((BSET)->e.elts)
95 #define EBITSET_SIZE(BSET) ((BSET)->e.size)
97 #define EBITSET_NEXT(ELT) ((ELT)->u.next)
98 #define EBITSET_WORDS(ELT) ((ELT)->u.words)
100 /* Disable bitset cache and mark BSET as being zero. */
101 #define EBITSET_ZERO_SET(BSET) ((BSET)->b.cindex = BITSET_WINDEX_MAX, \
104 #define EBITSET_CACHE_DISABLE(BSET) ((BSET)->b.cindex = BITSET_WINDEX_MAX)
106 /* Disable bitset cache and mark BSET as being possibly non-zero. */
107 #define EBITSET_NONZERO_SET(BSET) \
108 (EBITSET_CACHE_DISABLE (BSET), (BSET)->b.cdata = (bitset_word *)~0)
110 /* A conservative estimate of whether the bitset is zero.
111 This is non-zero only if we know for sure that the bitset is zero. */
112 #define EBITSET_ZERO_P(BSET) ((BSET)->b.cdata == 0)
114 /* Enable cache to point to element with table index EINDEX.
115 The element must exist. */
116 #define EBITSET_CACHE_SET(BSET, EINDEX) \
117 ((BSET)->b.cindex = (EINDEX) * EBITSET_ELT_WORDS, \
118 (BSET)->b.cdata = EBITSET_WORDS (EBITSET_ELTS (BSET) [EINDEX]))
121 /* Grow the expandable table for BSET by SIZE elements. */
123 ebitset_elts_grow (bitset bset
, bitset_windex size
)
125 bitset_windex oldsize
;
126 bitset_windex newsize
;
128 oldsize
= EBITSET_SIZE (bset
);
129 newsize
= oldsize
+ size
;
131 if (BITSET_SIZE_MAX
/ sizeof (ebitset_elt
*) < newsize
)
134 EBITSET_ELTS (bset
) = xrealloc (EBITSET_ELTS (bset
),
135 newsize
* sizeof (ebitset_elt
*));
136 EBITSET_SIZE (bset
) = newsize
;
138 memset (EBITSET_ELTS (bset
) + oldsize
, 0, size
* sizeof (ebitset_elt
*));
142 /* Allocate a ebitset element. The bits are not cleared. */
143 static inline ebitset_elt
*
144 ebitset_elt_alloc (void)
148 if (ebitset_free_list
!= 0)
150 elt
= ebitset_free_list
;
151 ebitset_free_list
= EBITSET_NEXT (elt
);
155 if (!ebitset_obstack_init
)
157 ebitset_obstack_init
= true;
159 /* Let particular systems override the size of a chunk. */
161 #ifndef OBSTACK_CHUNK_SIZE
162 #define OBSTACK_CHUNK_SIZE 0
165 /* Let them override the alloc and free routines too. */
167 #ifndef OBSTACK_CHUNK_ALLOC
168 #define OBSTACK_CHUNK_ALLOC xmalloc
171 #ifndef OBSTACK_CHUNK_FREE
172 #define OBSTACK_CHUNK_FREE free
175 #if !defined(__GNUC__) || (__GNUC__ < 2)
176 #define __alignof__(type) 0
179 obstack_specify_allocation (&ebitset_obstack
, OBSTACK_CHUNK_SIZE
,
180 __alignof__ (ebitset_elt
),
181 (void *(*)PARAMS ((long)))
183 (void (*)PARAMS ((void *)))
187 /* Perhaps we should add a number of new elements to the free
189 elt
= (ebitset_elt
*) obstack_alloc (&ebitset_obstack
,
190 sizeof (ebitset_elt
));
197 /* Allocate a ebitset element. The bits are cleared. */
198 static inline ebitset_elt
*
199 ebitset_elt_calloc (void)
203 elt
= ebitset_elt_alloc ();
204 memset (EBITSET_WORDS (elt
), 0, sizeof (EBITSET_WORDS (elt
)));
210 ebitset_elt_free (ebitset_elt
*elt
)
212 EBITSET_NEXT (elt
) = ebitset_free_list
;
213 ebitset_free_list
= elt
;
217 /* Remove element with index EINDEX from bitset BSET. */
219 ebitset_elt_remove (bitset bset
, bitset_windex eindex
)
224 elts
= EBITSET_ELTS (bset
);
229 ebitset_elt_free (elt
);
233 /* Add ELT into elts at index EINDEX of bitset BSET. */
235 ebitset_elt_add (bitset bset
, ebitset_elt
*elt
, bitset_windex eindex
)
239 elts
= EBITSET_ELTS (bset
);
240 /* Assume that the elts entry not allocated. */
245 /* Are all bits in an element zero? */
247 ebitset_elt_zero_p (ebitset_elt
*elt
)
251 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
252 if (EBITSET_WORDS (elt
)[i
])
260 ebitset_elt_find (bitset bset
, bitset_windex windex
,
261 enum ebitset_find_mode mode
)
265 bitset_windex eindex
;
268 eindex
= windex
/ EBITSET_ELT_WORDS
;
270 elts
= EBITSET_ELTS (bset
);
271 size
= EBITSET_SIZE (bset
);
275 if ((elt
= elts
[eindex
]))
277 if (EBITSET_WORDS (elt
) == bset
->b
.cdata
)
280 EBITSET_CACHE_SET (bset
, eindex
);
285 /* The element could not be found. */
297 extra
= eindex
- size
+ 1;
299 /* We need to expand the table by EXTRA elements. It may be
300 better with large bitsets to grow the number of
301 elements by some fraction of the current size otherwise
302 we can spend a lot of time slowly increasing the size of the
304 if (extra
< EBITSET_GROW_SIZE
)
305 extra
= EBITSET_GROW_SIZE
;
307 ebitset_elts_grow (bset
, extra
);
310 /* Create a new element. */
311 elt
= ebitset_elt_calloc ();
312 ebitset_elt_add (bset
, elt
, eindex
);
313 EBITSET_CACHE_SET (bset
, eindex
);
317 return &ebitset_zero_elts
[0];
325 static inline ebitset_elt
*
326 ebitset_elt_last (bitset bset
)
330 elts
= EBITSET_ELTS (bset
);
332 /* Assume that have at least one element in elts. */
333 return elts
[EBITSET_SIZE (bset
) - 1];
337 /* Weed out the zero elements from the elts. */
338 static inline bitset_windex
339 ebitset_weed (bitset bset
)
345 if (EBITSET_ZERO_P (bset
))
348 elts
= EBITSET_ELTS (bset
);
350 for (j
= 0; j
< EBITSET_SIZE (bset
); j
++)
352 ebitset_elt
*elt
= elts
[j
];
356 if (elt
&& ebitset_elt_zero_p (elt
))
358 ebitset_elt_remove (bset
, j
);
369 /* All the bits are zero. We could shrink the elts.
370 For now just mark BSET as known to be zero. */
371 EBITSET_ZERO_SET (bset
);
374 EBITSET_NONZERO_SET (bset
);
380 /* Set all bits in the bitset to zero. */
382 ebitset_zero (bitset bset
)
387 if (EBITSET_ZERO_P (bset
))
390 elts
= EBITSET_ELTS (bset
);
391 for (j
= 0; j
< EBITSET_SIZE (bset
); j
++)
393 ebitset_elt
*elt
= elts
[j
];
396 ebitset_elt_remove (bset
, j
);
399 /* All the bits are zero. We could shrink the elts.
400 For now just mark BSET as known to be zero. */
401 EBITSET_ZERO_SET (bset
);
406 ebitset_equal_p (bitset dst
, bitset src
)
418 if (EBITSET_SIZE (src
) != EBITSET_SIZE (dst
))
421 selts
= EBITSET_ELTS (src
);
422 delts
= EBITSET_ELTS (dst
);
424 for (j
= 0; j
< EBITSET_SIZE (src
); j
++)
427 ebitset_elt
*selt
= selts
[j
];
428 ebitset_elt
*delt
= delts
[j
];
432 if ((selt
&& !delt
) || (!selt
&& delt
))
435 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
436 if (EBITSET_WORDS (selt
)[i
] != EBITSET_WORDS (delt
)[i
])
443 /* Copy bits from bitset SRC to bitset DST. */
445 ebitset_copy_ (bitset dst
, bitset src
)
456 if (EBITSET_SIZE (dst
) < EBITSET_SIZE (src
))
457 ebitset_elts_grow (dst
, EBITSET_SIZE (src
) - EBITSET_SIZE (dst
));
459 selts
= EBITSET_ELTS (src
);
460 delts
= EBITSET_ELTS (dst
);
461 for (j
= 0; j
< EBITSET_SIZE (src
); j
++)
463 ebitset_elt
*selt
= selts
[j
];
469 tmp
= ebitset_elt_alloc ();
471 memcpy (EBITSET_WORDS (tmp
), EBITSET_WORDS (selt
),
472 sizeof (EBITSET_WORDS (selt
)));
475 EBITSET_NONZERO_SET (dst
);
479 /* Copy bits from bitset SRC to bitset DST. Return true if
480 bitsets different. */
482 ebitset_copy_cmp (bitset dst
, bitset src
)
487 if (EBITSET_ZERO_P (dst
))
489 ebitset_copy_ (dst
, src
);
490 return !EBITSET_ZERO_P (src
);
493 if (ebitset_equal_p (dst
, src
))
496 ebitset_copy_ (dst
, src
);
501 /* Return size in bits of bitset SRC. */
503 ebitset_size (bitset src
)
505 /* Return current size of bitset in bits. */
506 return EBITSET_SIZE (src
) * EBITSET_ELT_BITS
;
510 /* Set bit BITNO in bitset DST. */
512 ebitset_set (bitset dst
, bitset_bindex bitno
)
514 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
516 ebitset_elt_find (dst
, windex
, EBITSET_CREATE
);
518 dst
->b
.cdata
[windex
- dst
->b
.cindex
] |=
519 (bitset_word
) 1 << (bitno
% BITSET_WORD_BITS
);
523 /* Reset bit BITNO in bitset DST. */
525 ebitset_reset (bitset dst
, bitset_bindex bitno
)
527 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
529 if (!ebitset_elt_find (dst
, windex
, EBITSET_FIND
))
532 dst
->b
.cdata
[windex
- dst
->b
.cindex
] &=
533 ~((bitset_word
) 1 << (bitno
% BITSET_WORD_BITS
));
535 /* If all the data is zero, perhaps we should remove it now...
536 However, there is a good chance that the element will be needed
541 /* Test bit BITNO in bitset SRC. */
543 ebitset_test (bitset src
, bitset_bindex bitno
)
545 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
547 return (ebitset_elt_find (src
, windex
, EBITSET_FIND
)
548 && ((src
->b
.cdata
[windex
- src
->b
.cindex
]
549 >> (bitno
% BITSET_WORD_BITS
))
555 ebitset_free (bitset bset
)
558 free (EBITSET_ELTS (bset
));
562 /* Find list of up to NUM bits set in BSET starting from and including
563 *NEXT and store in array LIST. Return with actual number of bits
564 found and with *NEXT indicating where search stopped. */
566 ebitset_list_reverse (bitset bset
, bitset_bindex
*list
,
567 bitset_bindex num
, bitset_bindex
*next
)
569 bitset_bindex n_bits
;
571 bitset_bindex rbitno
;
573 bitset_bindex boffset
;
574 bitset_windex windex
;
575 bitset_windex eindex
;
576 bitset_windex woffset
;
581 if (EBITSET_ZERO_P (bset
))
584 size
= EBITSET_SIZE (bset
);
585 n_bits
= size
* EBITSET_ELT_BITS
;
588 if (rbitno
>= n_bits
)
591 elts
= EBITSET_ELTS (bset
);
593 bitno
= n_bits
- (rbitno
+ 1);
595 windex
= bitno
/ BITSET_WORD_BITS
;
596 eindex
= bitno
/ EBITSET_ELT_BITS
;
597 woffset
= windex
- eindex
* EBITSET_ELT_WORDS
;
599 /* If num is 1, we could speed things up with a binary search
600 of the word of interest. */
603 bcount
= bitno
% BITSET_WORD_BITS
;
604 boffset
= windex
* BITSET_WORD_BITS
;
614 srcp
= EBITSET_WORDS (elt
);
620 word
= srcp
[woffset
] << (BITSET_WORD_BITS
- 1 - bcount
);
622 for (; word
; bcount
--)
624 if (word
& BITSET_MSB
)
626 list
[count
++] = boffset
+ bcount
;
629 *next
= n_bits
- (boffset
+ bcount
);
635 boffset
-= BITSET_WORD_BITS
;
636 bcount
= BITSET_WORD_BITS
- 1;
641 woffset
= EBITSET_ELT_WORDS
- 1;
642 boffset
= eindex
* EBITSET_ELT_BITS
- BITSET_WORD_BITS
;
646 *next
= n_bits
- (boffset
+ 1);
651 /* Find list of up to NUM bits set in BSET starting from and including
652 *NEXT and store in array LIST. Return with actual number of bits
653 found and with *NEXT indicating where search stopped. */
655 ebitset_list (bitset bset
, bitset_bindex
*list
,
656 bitset_bindex num
, bitset_bindex
*next
)
659 bitset_windex windex
;
660 bitset_windex eindex
;
667 if (EBITSET_ZERO_P (bset
))
673 elts
= EBITSET_ELTS (bset
);
674 size
= EBITSET_SIZE (bset
);
675 eindex
= bitno
/ EBITSET_ELT_BITS
;
677 if (bitno
% EBITSET_ELT_BITS
)
679 /* We need to start within an element. This is not very common. */
684 bitset_windex woffset
;
685 bitset_word
*srcp
= EBITSET_WORDS (elt
);
687 windex
= bitno
/ BITSET_WORD_BITS
;
688 woffset
= eindex
* EBITSET_ELT_WORDS
;
690 for (; (windex
- woffset
) < EBITSET_ELT_WORDS
; windex
++)
692 word
= srcp
[windex
- woffset
] >> (bitno
% BITSET_WORD_BITS
);
694 for (; word
; bitno
++)
698 list
[count
++] = bitno
;
707 bitno
= (windex
+ 1) * BITSET_WORD_BITS
;
711 /* Skip to next element. */
715 /* If num is 1, we could speed things up with a binary search
716 of the word of interest. */
718 for (; eindex
< size
; eindex
++)
727 srcp
= EBITSET_WORDS (elt
);
728 windex
= eindex
* EBITSET_ELT_WORDS
;
730 if ((count
+ EBITSET_ELT_BITS
) < num
)
732 /* The coast is clear, plant boot! */
734 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, windex
++)
736 bitno
= windex
* BITSET_WORD_BITS
;
741 if (!(word
& 0xffff))
751 for (; word
; bitno
++)
754 list
[count
++] = bitno
;
762 /* Tread more carefully since we need to check
763 if array overflows. */
765 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, windex
++)
767 bitno
= windex
* BITSET_WORD_BITS
;
769 for (word
= srcp
[i
]; word
; bitno
++)
773 list
[count
++] = bitno
;
792 ebitset_ones (bitset dst
)
798 for (j
= 0; j
< EBITSET_SIZE (dst
); j
++)
800 /* Create new elements if they cannot be found. Perhaps
801 we should just add pointers to a ones element. */
803 ebitset_elt_find (dst
, j
* EBITSET_ELT_WORDS
, EBITSET_CREATE
);
804 memset (EBITSET_WORDS (elt
), -1, sizeof (EBITSET_WORDS (elt
)));
806 EBITSET_NONZERO_SET (dst
);
811 ebitset_empty_p (bitset dst
)
813 return !ebitset_weed (dst
);
818 ebitset_not (bitset dst
, bitset src
)
825 for (j
= 0; j
< EBITSET_SIZE (src
); j
++)
827 /* Create new elements for dst if they cannot be found
828 or substitute zero elements if src elements not found. */
830 ebitset_elt_find (dst
, j
* EBITSET_ELT_WORDS
, EBITSET_SUBST
);
832 ebitset_elt_find (dst
, j
* EBITSET_ELT_WORDS
, EBITSET_CREATE
);
834 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
835 EBITSET_WORDS (delt
)[i
] = ~EBITSET_WORDS (selt
)[i
];
837 EBITSET_NONZERO_SET (dst
);
841 /* Is DST == DST | SRC? */
843 ebitset_subset_p (bitset dst
, bitset src
)
851 selts
= EBITSET_ELTS (src
);
852 delts
= EBITSET_ELTS (dst
);
854 ssize
= EBITSET_SIZE (src
);
855 dsize
= EBITSET_SIZE (dst
);
857 for (j
= 0; j
< ssize
; j
++)
863 selt
= j
< ssize
? selts
[j
] : 0;
864 delt
= j
< dsize
? delts
[j
] : 0;
870 selt
= &ebitset_zero_elts
[0];
872 delt
= &ebitset_zero_elts
[0];
874 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
875 if (EBITSET_WORDS (delt
)[i
]
876 != (EBITSET_WORDS (selt
)[i
] | EBITSET_WORDS (delt
)[i
]))
883 /* Is DST & SRC == 0? */
885 ebitset_disjoint_p (bitset dst
, bitset src
)
893 selts
= EBITSET_ELTS (src
);
894 delts
= EBITSET_ELTS (dst
);
896 ssize
= EBITSET_SIZE (src
);
897 dsize
= EBITSET_SIZE (dst
);
899 for (j
= 0; j
< ssize
; j
++)
905 selt
= j
< ssize
? selts
[j
] : 0;
906 delt
= j
< dsize
? delts
[j
] : 0;
911 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
912 if ((EBITSET_WORDS (selt
)[i
] & EBITSET_WORDS (delt
)[i
]))
921 ebitset_op3_cmp (bitset dst
, bitset src1
, bitset src2
, enum bitset_ops op
)
923 bitset_windex ssize1
;
924 bitset_windex ssize2
;
927 ebitset_elts
*selts1
;
928 ebitset_elts
*selts2
;
933 bool changed
= false;
937 ssize1
= EBITSET_SIZE (src1
);
938 ssize2
= EBITSET_SIZE (src2
);
939 dsize
= EBITSET_SIZE (dst
);
945 ebitset_elts_grow (dst
, size
- dsize
);
947 selts1
= EBITSET_ELTS (src1
);
948 selts2
= EBITSET_ELTS (src2
);
949 delts
= EBITSET_ELTS (dst
);
951 for (j
= 0; j
< size
; j
++)
957 selt1
= j
< ssize1
? selts1
[j
] : 0;
958 selt2
= j
< ssize2
? selts2
[j
] : 0;
959 delt
= j
< dsize
? delts
[j
] : 0;
961 if (!selt1
&& !selt2
)
966 ebitset_elt_remove (dst
, j
);
972 selt1
= &ebitset_zero_elts
[0];
974 selt2
= &ebitset_zero_elts
[0];
976 delt
= ebitset_elt_calloc ();
980 srcp1
= EBITSET_WORDS (selt1
);
981 srcp2
= EBITSET_WORDS (selt2
);
982 dstp
= EBITSET_WORDS (delt
);
986 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
988 bitset_word tmp
= *srcp1
++ | *srcp2
++;
999 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1001 bitset_word tmp
= *srcp1
++ & *srcp2
++;
1012 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1014 bitset_word tmp
= *srcp1
++ ^ *srcp2
++;
1024 case BITSET_OP_ANDN
:
1025 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1027 bitset_word tmp
= *srcp1
++ & ~(*srcp2
++);
1041 if (!ebitset_elt_zero_p (delt
))
1043 ebitset_elt_add (dst
, delt
, j
);
1047 ebitset_elt_free (delt
);
1051 /* If we have elements of DST left over, free them all. */
1052 for (; j
< dsize
; j
++)
1061 ebitset_elt_remove (dst
, j
);
1064 EBITSET_NONZERO_SET (dst
);
1070 ebitset_and_cmp (bitset dst
, bitset src1
, bitset src2
)
1074 if (EBITSET_ZERO_P (src2
))
1077 changed
= EBITSET_ZERO_P (dst
);
1081 else if (EBITSET_ZERO_P (src1
))
1084 changed
= EBITSET_ZERO_P (dst
);
1088 return ebitset_op3_cmp (dst
, src1
, src2
, BITSET_OP_AND
);
1093 ebitset_and (bitset dst
, bitset src1
, bitset src2
)
1095 ebitset_and_cmp (dst
, src1
, src2
);
1100 ebitset_andn_cmp (bitset dst
, bitset src1
, bitset src2
)
1104 if (EBITSET_ZERO_P (src2
))
1106 return ebitset_copy_cmp (dst
, src1
);
1108 else if (EBITSET_ZERO_P (src1
))
1111 changed
= EBITSET_ZERO_P (dst
);
1115 return ebitset_op3_cmp (dst
, src1
, src2
, BITSET_OP_ANDN
);
1120 ebitset_andn (bitset dst
, bitset src1
, bitset src2
)
1122 ebitset_andn_cmp (dst
, src1
, src2
);
1127 ebitset_or_cmp (bitset dst
, bitset src1
, bitset src2
)
1129 if (EBITSET_ZERO_P (src2
))
1131 return ebitset_copy_cmp (dst
, src1
);
1133 else if (EBITSET_ZERO_P (src1
))
1135 return ebitset_copy_cmp (dst
, src2
);
1137 return ebitset_op3_cmp (dst
, src1
, src2
, BITSET_OP_OR
);
1142 ebitset_or (bitset dst
, bitset src1
, bitset src2
)
1144 ebitset_or_cmp (dst
, src1
, src2
);
1149 ebitset_xor_cmp (bitset dst
, bitset src1
, bitset src2
)
1151 if (EBITSET_ZERO_P (src2
))
1153 return ebitset_copy_cmp (dst
, src1
);
1155 else if (EBITSET_ZERO_P (src1
))
1157 return ebitset_copy_cmp (dst
, src2
);
1159 return ebitset_op3_cmp (dst
, src1
, src2
, BITSET_OP_XOR
);
1164 ebitset_xor (bitset dst
, bitset src1
, bitset src2
)
1166 ebitset_xor_cmp (dst
, src1
, src2
);
1171 ebitset_copy (bitset dst
, bitset src
)
1173 if (BITSET_COMPATIBLE_ (dst
, src
))
1174 ebitset_copy_ (dst
, src
);
1176 bitset_copy_ (dst
, src
);
1180 /* Vector of operations for linked-list bitsets. */
1181 struct bitset_vtable ebitset_vtable
= {
1207 bitset_andn_or_cmp_
,
1211 ebitset_list_reverse
,
1217 /* Return size of initial structure. */
1219 ebitset_bytes (bitset_bindex n_bits ATTRIBUTE_UNUSED
)
1221 return sizeof (struct ebitset_struct
);
1225 /* Initialize a bitset. */
1228 ebitset_init (bitset bset
, bitset_bindex n_bits
)
1232 bset
->b
.vtable
= &ebitset_vtable
;
1234 bset
->b
.csize
= EBITSET_ELT_WORDS
;
1236 EBITSET_ZERO_SET (bset
);
1238 size
= n_bits
? (n_bits
+ EBITSET_ELT_BITS
- 1) / EBITSET_ELT_BITS
1239 : EBITSET_INITIAL_SIZE
;
1241 EBITSET_SIZE (bset
) = 0;
1242 EBITSET_ELTS (bset
) = 0;
1243 ebitset_elts_grow (bset
, size
);
1250 ebitset_release_memory (void)
1252 ebitset_free_list
= 0;
1253 if (ebitset_obstack_init
)
1255 ebitset_obstack_init
= false;
1256 obstack_free (&ebitset_obstack
, NULL
);