1 /* Functions to support expandable bitsets.
2 Copyright (C) 2002 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 some large number 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
;
71 /* Head of ebitset linked list. */
72 typedef struct ebitset_struct
74 unsigned int size
; /* Number of elements. */
75 ebitset_elts
*elts
; /* Expanding array of pointers to elements. */
80 /* Number of elements to initially allocate. */
82 #ifndef EBITSET_INITIAL_SIZE
83 #define EBITSET_INITIAL_SIZE 2
86 /* Minimum number of elements to grow table. */
88 #ifndef EBITSET_GROW_SIZE
89 #define EBITSET_GROW_SIZE 4
94 struct bbitset_struct b
;
95 struct ebitset_struct e
;
98 enum ebitset_find_mode
99 { EBITSET_FIND
, EBITSET_CREATE
, EBITSET_SUBST
};
101 static ebitset_elt ebitset_zero_elts
[1]; /* Elements of all zero bits. */
103 /* Obstack to allocate bitset elements from. */
104 static struct obstack ebitset_obstack
;
105 static int ebitset_obstack_init
= 0;
106 static ebitset_elt
*ebitset_free_list
; /* Free list of bitset elements. */
108 static void ebitset_elts_grow
PARAMS ((bitset
, unsigned int));
109 static ebitset_elt
*ebitset_elt_alloc
PARAMS ((void));
110 static ebitset_elt
*ebitset_elt_calloc
PARAMS ((void));
111 static void ebitset_elt_add
PARAMS ((bitset
, ebitset_elt
*, unsigned int));
112 static void ebitset_elt_remove
PARAMS ((bitset
, unsigned int));
113 static void ebitset_elt_free
PARAMS ((ebitset_elt
*));
114 static ebitset_elt
*ebitset_elt_find
PARAMS ((bitset
, bitset_windex
,
115 enum ebitset_find_mode
));
116 static ebitset_elt
*ebitset_elt_last
PARAMS ((bitset
));
117 static int ebitset_elt_zero_p
PARAMS ((ebitset_elt
*));
119 static int ebitset_weed
PARAMS ((bitset
));
120 static void ebitset_zero
PARAMS ((bitset
));
121 static int ebitset_equal_p
PARAMS ((bitset
, bitset
));
122 static void ebitset_copy
PARAMS ((bitset
, bitset
));
123 static int ebitset_copy_compare
PARAMS ((bitset
, bitset
));
124 static void ebitset_set
PARAMS ((bitset
, bitset_bindex
));
125 static void ebitset_reset
PARAMS ((bitset
, bitset_bindex
));
126 static int ebitset_test
PARAMS ((bitset
, bitset_bindex
));
127 static int ebitset_size
PARAMS ((bitset
));
128 static int ebitset_op1
PARAMS ((bitset
, enum bitset_ops
));
129 static int ebitset_op2
PARAMS ((bitset
, bitset
, enum bitset_ops
));
130 static int ebitset_op3
PARAMS ((bitset
, bitset
, bitset
, enum bitset_ops
));
131 static int ebitset_list
PARAMS ((bitset
, bitset_bindex
*, bitset_bindex
,
133 static int ebitset_reverse_list
134 PARAMS ((bitset
, bitset_bindex
*, bitset_bindex
, bitset_bindex
*));
135 static void ebitset_free
PARAMS ((bitset
));
137 #define EBITSET_ELTS(BSET) ((BSET)->e.elts)
138 #define EBITSET_SIZE(BSET) ((BSET)->e.size)
140 #define EBITSET_NEXT(ELT) ((ELT)->u.next)
141 #define EBITSET_WORDS(ELT) ((ELT)->u.words)
143 /* Disable bitset cache and mark BSET as being zero. */
144 #define EBITSET_OP_ZERO_SET(BSET) ((BSET)->b.cindex = BITSET_INDEX_MAX, \
147 #define EBITSET_CACHE_DISABLE(BSET) ((BSET)->b.cindex = BITSET_INDEX_MAX)
149 /* Disable bitset cache and mark BSET as being possibly non-zero. */
150 #define EBITSET_NONZERO_SET(BSET) \
151 (EBITSET_CACHE_DISABLE (BSET), (BSET)->b.cdata = (bitset_word *)~0)
153 /* A conservative estimate of whether the bitset is zero.
154 This is non-zero only if we know for sure that the bitset is zero. */
155 #define EBITSET_OP_ZERO_P(BSET) ((BSET)->b.cdata == 0)
157 /* Enable cache to point to element with table index EINDEX.
158 The element must exist. */
159 #define EBITSET_CACHE_SET(BSET, EINDEX) \
160 ((BSET)->b.cindex = (EINDEX) * EBITSET_ELT_WORDS, \
161 (BSET)->b.cdata = EBITSET_WORDS (EBITSET_ELTS (BSET) [EINDEX]))
164 /* Grow the expandable table for BSET by SIZE elements. */
166 ebitset_elts_grow (bset
, size
)
170 unsigned int oldsize
;
171 unsigned int newsize
;
173 oldsize
= EBITSET_SIZE (bset
);
174 newsize
= oldsize
+ size
;
176 EBITSET_ELTS (bset
) = xrealloc (EBITSET_ELTS (bset
),
177 newsize
* sizeof (ebitset_elt
*));
178 EBITSET_SIZE (bset
) = newsize
;
180 memset (EBITSET_ELTS (bset
) + oldsize
, 0, size
* sizeof (ebitset_elt
*));
184 /* Allocate a ebitset element. The bits are not cleared. */
185 static inline ebitset_elt
*
190 if (ebitset_free_list
!= 0)
192 elt
= ebitset_free_list
;
193 ebitset_free_list
= EBITSET_NEXT (elt
);
197 if (!ebitset_obstack_init
)
199 ebitset_obstack_init
= 1;
201 /* Let particular systems override the size of a chunk. */
203 #ifndef OBSTACK_CHUNK_SIZE
204 #define OBSTACK_CHUNK_SIZE 0
207 /* Let them override the alloc and free routines too. */
209 #ifndef OBSTACK_CHUNK_ALLOC
210 #define OBSTACK_CHUNK_ALLOC xmalloc
213 #ifndef OBSTACK_CHUNK_FREE
214 #define OBSTACK_CHUNK_FREE free
217 #if !defined(__GNUC__) || (__GNUC__ < 2)
218 #define __alignof__(type) 0
221 obstack_specify_allocation (&ebitset_obstack
, OBSTACK_CHUNK_SIZE
,
222 __alignof__ (ebitset_elt
),
223 (void *(*)PARAMS ((long)))
225 (void (*)PARAMS ((void *)))
229 /* Perhaps we should add a number of new elements to the free
231 elt
= (ebitset_elt
*) obstack_alloc (&ebitset_obstack
,
232 sizeof (ebitset_elt
));
239 /* Allocate a ebitset element. The bits are cleared. */
240 static inline ebitset_elt
*
241 ebitset_elt_calloc ()
245 elt
= ebitset_elt_alloc ();
246 memset (EBITSET_WORDS (elt
), 0, sizeof (EBITSET_WORDS (elt
)));
252 ebitset_elt_free (elt
)
255 EBITSET_NEXT (elt
) = ebitset_free_list
;
256 ebitset_free_list
= elt
;
260 /* Remove element with index EINDEX from bitset BSET. */
262 ebitset_elt_remove (bset
, eindex
)
269 elts
= EBITSET_ELTS (bset
);
274 ebitset_elt_free (elt
);
278 /* Add ELT into elts at index EINDEX of bitset BSET. */
280 ebitset_elt_add (bset
, elt
, eindex
)
287 elts
= EBITSET_ELTS (bset
);
288 /* Assume that the elts entry not allocated. */
293 /* Return nonzero if all bits in an element are zero. */
295 ebitset_elt_zero_p (elt
)
300 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
301 if (EBITSET_WORDS (elt
)[i
])
309 ebitset_elt_find (bset
, windex
, mode
)
311 bitset_windex windex
;
312 enum ebitset_find_mode mode
;
319 eindex
= windex
/ EBITSET_ELT_WORDS
;
321 elts
= EBITSET_ELTS (bset
);
322 size
= EBITSET_SIZE (bset
);
326 if ((elt
= elts
[eindex
]))
328 if (EBITSET_WORDS (elt
) == bset
->b
.cdata
)
331 EBITSET_CACHE_SET (bset
, eindex
);
336 /* The element could not be found. */
348 extra
= eindex
- size
+ 1;
350 /* We need to expand the table by EXTRA elements. It may be
351 better with large bitsets to grow the number of
352 elements by some fraction of the current size otherwise
353 we can spend a lot of time slowly increasing the size of the
355 if (extra
< EBITSET_GROW_SIZE
)
356 extra
= EBITSET_GROW_SIZE
;
358 ebitset_elts_grow (bset
, extra
);
361 /* Create a new element. */
362 elt
= ebitset_elt_calloc ();
363 ebitset_elt_add (bset
, elt
, eindex
);
364 EBITSET_CACHE_SET (bset
, eindex
);
368 return &ebitset_zero_elts
[0];
376 static inline ebitset_elt
*
377 ebitset_elt_last (bset
)
382 elts
= EBITSET_ELTS (bset
);
384 /* Assume that have at least one element in elts. */
385 return elts
[EBITSET_SIZE (bset
) - 1];
389 /* Weed out the zero elements from the elts. */
398 if (EBITSET_OP_ZERO_P (bset
))
401 elts
= EBITSET_ELTS (bset
);
403 for (j
= 0; j
< EBITSET_SIZE (bset
); j
++)
405 ebitset_elt
*elt
= elts
[j
];
409 if (elt
&& ebitset_elt_zero_p (elt
))
411 ebitset_elt_remove (bset
, j
);
422 /* All the bits are zero. We could shrink the elts.
423 For now just mark BSET as known to be zero. */
424 EBITSET_OP_ZERO_SET (bset
);
427 EBITSET_NONZERO_SET (bset
);
433 /* Set all bits in the bitset to zero. */
441 if (EBITSET_OP_ZERO_P (bset
))
444 elts
= EBITSET_ELTS (bset
);
445 for (j
= 0; j
< EBITSET_SIZE (bset
); j
++)
447 ebitset_elt
*elt
= elts
[j
];
450 ebitset_elt_remove (bset
, j
);
453 /* All the bits are zero. We could shrink the elts.
454 For now just mark BSET as known to be zero. */
455 EBITSET_OP_ZERO_SET (bset
);
460 ebitset_equal_p (dst
, src
)
474 if (EBITSET_SIZE (src
) != EBITSET_SIZE (dst
))
477 selts
= EBITSET_ELTS (src
);
478 delts
= EBITSET_ELTS (dst
);
480 for (j
= 0; j
< EBITSET_SIZE (src
); j
++)
483 ebitset_elt
*selt
= selts
[j
];
484 ebitset_elt
*delt
= delts
[j
];
488 if ((selt
&& !delt
) || (!selt
&& delt
))
491 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
492 if (EBITSET_WORDS (selt
)[i
] != EBITSET_WORDS (delt
)[i
])
499 /* Copy bits from bitset SRC to bitset DST. */
501 ebitset_copy (dst
, src
)
514 if (EBITSET_SIZE (dst
) < EBITSET_SIZE (src
))
515 ebitset_elts_grow (dst
, EBITSET_SIZE (src
) - EBITSET_SIZE (dst
));
517 selts
= EBITSET_ELTS (src
);
518 delts
= EBITSET_ELTS (dst
);
519 for (j
= 0; j
< EBITSET_SIZE (src
); j
++)
521 ebitset_elt
*selt
= selts
[j
];
527 tmp
= ebitset_elt_alloc ();
529 memcpy (EBITSET_WORDS (tmp
), EBITSET_WORDS (selt
),
530 sizeof (EBITSET_WORDS (selt
)));
533 EBITSET_NONZERO_SET (dst
);
537 /* Copy bits from bitset SRC to bitset DST. Return non-zero if
538 bitsets different. */
540 ebitset_copy_compare (dst
, src
)
547 if (EBITSET_OP_ZERO_P (dst
))
549 ebitset_copy (dst
, src
);
550 return !EBITSET_OP_ZERO_P (src
);
553 if (ebitset_equal_p (dst
, src
))
556 ebitset_copy (dst
, src
);
561 /* Return size in bits of bitset SRC. */
566 /* Return current size of bitset in bits. */
567 return EBITSET_SIZE (src
) * EBITSET_ELT_BITS
;
571 /* Set bit BITNO in bitset DST. */
573 ebitset_set (dst
, bitno
)
577 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
579 ebitset_elt_find (dst
, windex
, EBITSET_CREATE
);
581 dst
->b
.cdata
[windex
- dst
->b
.cindex
] |=
582 (bitset_word
) 1 << (bitno
% BITSET_WORD_BITS
);
586 /* Reset bit BITNO in bitset DST. */
588 ebitset_reset (dst
, bitno
)
592 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
594 if (!ebitset_elt_find (dst
, windex
, EBITSET_FIND
))
597 dst
->b
.cdata
[windex
- dst
->b
.cindex
] &=
598 ~((bitset_word
) 1 << (bitno
% BITSET_WORD_BITS
));
600 /* If all the data is zero, perhaps we should remove it now...
601 However, there is a good chance that the element will be needed
606 /* Test bit BITNO in bitset SRC. */
608 ebitset_test (src
, bitno
)
612 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
614 if (!ebitset_elt_find (src
, windex
, EBITSET_FIND
))
618 cdata
[windex
- src
->b
.cindex
] >> (bitno
% BITSET_WORD_BITS
)) & 1;
627 free (EBITSET_ELTS (bset
));
631 /* Find list of up to NUM bits set in BSET starting from and including
632 *NEXT and store in array LIST. Return with actual number of bits
633 found and with *NEXT indicating where search stopped. */
635 ebitset_reverse_list (bset
, list
, num
, next
)
641 bitset_bindex n_bits
;
643 bitset_bindex rbitno
;
645 bitset_bindex boffset
;
646 bitset_windex windex
;
648 bitset_windex woffset
;
653 if (EBITSET_OP_ZERO_P (bset
))
656 size
= EBITSET_SIZE (bset
);
657 n_bits
= size
* EBITSET_ELT_BITS
;
660 if (rbitno
>= n_bits
)
663 elts
= EBITSET_ELTS (bset
);
665 bitno
= n_bits
- (rbitno
+ 1);
667 windex
= bitno
/ BITSET_WORD_BITS
;
668 eindex
= bitno
/ EBITSET_ELT_BITS
;
669 woffset
= windex
- eindex
* EBITSET_ELT_WORDS
;
671 /* If num is 1, we could speed things up with a binary search
672 of the word of interest. */
675 bcount
= bitno
% BITSET_WORD_BITS
;
676 boffset
= windex
* BITSET_WORD_BITS
;
687 srcp
= EBITSET_WORDS (elt
);
693 word
= srcp
[woffset
] << (BITSET_WORD_BITS
- 1 - bcount
);
695 for (; word
; bcount
--)
697 if (word
& BITSET_MSB
)
699 list
[count
++] = boffset
+ bcount
;
702 *next
= n_bits
- (boffset
+ bcount
);
709 boffset
-= BITSET_WORD_BITS
;
710 bcount
= BITSET_WORD_BITS
- 1;
714 woffset
= EBITSET_ELT_WORDS
;
717 boffset
= eindex
* EBITSET_ELT_BITS
- BITSET_WORD_BITS
;
721 *next
= n_bits
- (boffset
+ 1);
726 /* Find list of up to NUM bits set in BSET starting from and including
727 *NEXT and store in array LIST. Return with actual number of bits
728 found and with *NEXT indicating where search stopped. */
730 ebitset_list (bset
, list
, num
, next
)
737 bitset_windex windex
;
745 if (EBITSET_OP_ZERO_P (bset
))
751 elts
= EBITSET_ELTS (bset
);
752 size
= EBITSET_SIZE (bset
);
753 eindex
= bitno
/ EBITSET_ELT_BITS
;
755 if (bitno
% EBITSET_ELT_BITS
)
757 /* We need to start within an element. This is not very common. */
762 bitset_windex woffset
;
763 bitset_word
*srcp
= EBITSET_WORDS (elt
);
765 windex
= bitno
/ BITSET_WORD_BITS
;
766 woffset
= eindex
/ EBITSET_ELT_WORDS
;
768 for (; (windex
- woffset
) < EBITSET_ELT_WORDS
; windex
++)
770 word
= srcp
[windex
- woffset
] >> (bitno
% BITSET_WORD_BITS
);
772 for (; word
; bitno
++)
776 list
[count
++] = bitno
;
785 bitno
= (windex
+ 1) * BITSET_WORD_BITS
;
789 /* Skip to next element. */
793 /* If num is 1, we could speed things up with a binary search
794 of the word of interest. */
796 for (; eindex
< size
; eindex
++)
805 srcp
= EBITSET_WORDS (elt
);
806 windex
= eindex
* EBITSET_ELT_WORDS
;
808 if ((count
+ EBITSET_ELT_BITS
) < num
)
810 /* The coast is clear, plant boot! */
812 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, windex
++)
814 bitno
= windex
* BITSET_WORD_BITS
;
819 if (!(word
& 0xffff))
829 for (; word
; bitno
++)
832 list
[count
++] = bitno
;
840 /* Tread more carefully since we need to check
841 if array overflows. */
843 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, windex
++)
845 bitno
= windex
* BITSET_WORD_BITS
;
847 for (word
= srcp
[i
]; word
; bitno
++)
851 list
[count
++] = bitno
;
870 ebitset_op1 (dst
, op
)
884 for (j
= 0; j
< EBITSET_SIZE (dst
); j
++)
886 /* Create new elements if they cannot be found. Perhaps
887 we should just add pointers to a ones element. */
889 ebitset_elt_find (dst
, j
* EBITSET_ELT_WORDS
, EBITSET_CREATE
);
890 memset (EBITSET_WORDS (elt
), -1, sizeof (EBITSET_WORDS (elt
)));
894 case BITSET_OP_EMPTY_P
:
895 return !ebitset_weed (dst
);
901 EBITSET_NONZERO_SET (dst
);
907 ebitset_op2 (dst
, src
, op
)
920 ebitset_copy (dst
, src
);
924 for (j
= 0; j
< EBITSET_SIZE (src
); j
++)
926 /* Create new elements for dst if they cannot be found
927 or substitute zero elements if src elements not found. */
929 ebitset_elt_find (dst
, j
* EBITSET_ELT_WORDS
, EBITSET_SUBST
);
931 ebitset_elt_find (dst
, j
* EBITSET_ELT_WORDS
, EBITSET_CREATE
);
933 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
934 EBITSET_WORDS (delt
)[i
] = ~EBITSET_WORDS (selt
)[i
];
938 /* Return 1 if DST == SRC. */
939 case BITSET_OP_EQUAL_P
:
940 return ebitset_equal_p (dst
, src
);
942 /* Return 1 if DST == DST | SRC. */
943 case BITSET_OP_SUBSET_P
:
950 selts
= EBITSET_ELTS (src
);
951 delts
= EBITSET_ELTS (dst
);
953 ssize
= EBITSET_SIZE (src
);
954 dsize
= EBITSET_SIZE (dst
);
956 for (j
= 0; j
< ssize
; j
++)
958 selt
= j
< ssize
? selts
[j
] : 0;
959 delt
= j
< dsize
? delts
[j
] : 0;
965 selt
= &ebitset_zero_elts
[0];
967 delt
= &ebitset_zero_elts
[0];
969 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
970 if (EBITSET_WORDS (delt
)[i
]
971 != (EBITSET_WORDS (selt
)[i
] | EBITSET_WORDS (delt
)[i
]))
978 /* Return 1 if DST & SRC == 0. */
979 case BITSET_OP_DISJOINT_P
:
986 selts
= EBITSET_ELTS (src
);
987 delts
= EBITSET_ELTS (dst
);
989 ssize
= EBITSET_SIZE (src
);
990 dsize
= EBITSET_SIZE (dst
);
992 for (j
= 0; j
< ssize
; j
++)
994 selt
= j
< ssize
? selts
[j
] : 0;
995 delt
= j
< dsize
? delts
[j
] : 0;
1000 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++)
1001 if ((EBITSET_WORDS (selt
)[i
] & EBITSET_WORDS (delt
)[i
]))
1012 EBITSET_NONZERO_SET (dst
);
1018 ebitset_op3 (dst
, src1
, src2
, op
)
1024 bitset_windex ssize1
;
1025 bitset_windex ssize2
;
1026 bitset_windex dsize
;
1028 ebitset_elts
*selts1
;
1029 ebitset_elts
*selts2
;
1030 ebitset_elts
*delts
;
1038 /* Fast track common, simple cases. */
1039 if (EBITSET_OP_ZERO_P (src2
))
1041 if (op
== BITSET_OP_AND
)
1044 changed
= EBITSET_OP_ZERO_P (dst
);
1048 else if (op
== BITSET_OP_ANDN
|| op
== BITSET_OP_OR
1049 || op
== BITSET_OP_XOR
)
1051 return ebitset_copy_compare (dst
, src1
);
1054 else if (EBITSET_OP_ZERO_P (src1
))
1056 if (op
== BITSET_OP_AND
|| op
== BITSET_OP_ANDN
)
1059 changed
= EBITSET_OP_ZERO_P (dst
);
1063 else if (op
== BITSET_OP_OR
|| op
== BITSET_OP_XOR
)
1065 return ebitset_copy_compare (dst
, src2
);
1069 ssize1
= EBITSET_SIZE (src1
);
1070 ssize2
= EBITSET_SIZE (src2
);
1071 dsize
= EBITSET_SIZE (dst
);
1077 ebitset_elts_grow (dst
, size
- dsize
);
1079 selts1
= EBITSET_ELTS (src1
);
1080 selts2
= EBITSET_ELTS (src2
);
1081 delts
= EBITSET_ELTS (dst
);
1083 for (j
= 0; j
< size
; j
++)
1089 selt1
= j
< ssize1
? selts1
[j
] : 0;
1090 selt2
= j
< ssize2
? selts2
[j
] : 0;
1091 delt
= j
< dsize
? delts
[j
] : 0;
1093 if (!selt1
&& !selt2
)
1098 ebitset_elt_remove (dst
, j
);
1104 selt1
= &ebitset_zero_elts
[0];
1106 selt2
= &ebitset_zero_elts
[0];
1108 delt
= ebitset_elt_calloc ();
1112 srcp1
= EBITSET_WORDS (selt1
);
1113 srcp2
= EBITSET_WORDS (selt2
);
1114 dstp
= EBITSET_WORDS (delt
);
1118 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1120 bitset_word tmp
= *srcp1
++ | *srcp2
++;
1131 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1133 bitset_word tmp
= *srcp1
++ & *srcp2
++;
1144 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1146 bitset_word tmp
= *srcp1
++ ^ *srcp2
++;
1156 case BITSET_OP_ANDN
:
1157 for (i
= 0; i
< EBITSET_ELT_WORDS
; i
++, dstp
++)
1159 bitset_word tmp
= *srcp1
++ & ~(*srcp2
++);
1173 if (!ebitset_elt_zero_p (delt
))
1175 ebitset_elt_add (dst
, delt
, j
);
1179 ebitset_elt_free (delt
);
1183 /* If we have elements of DST left over, free them all. */
1184 for (; j
< dsize
; j
++)
1193 ebitset_elt_remove (dst
, j
);
1196 EBITSET_NONZERO_SET (dst
);
1201 /* Vector of operations for linked-list bitsets. */
1202 struct bitset_ops_struct ebitset_ops
= {
1212 ebitset_reverse_list
,
1218 /* Return size of initial structure. */
1220 ebitset_bytes (n_bits
)
1221 bitset_bindex n_bits ATTRIBUTE_UNUSED
;
1223 return sizeof (struct bitset_struct
);
1227 /* Initialize a bitset. */
1230 ebitset_init (bset
, n_bits
)
1232 bitset_bindex n_bits
;
1236 bset
->b
.ops
= &ebitset_ops
;
1238 bset
->b
.csize
= EBITSET_ELT_WORDS
;
1240 EBITSET_OP_ZERO_SET (bset
);
1242 size
= n_bits
? (n_bits
+ EBITSET_ELT_BITS
- 1) / EBITSET_ELT_BITS
1243 : EBITSET_INITIAL_SIZE
;
1245 EBITSET_SIZE (bset
) = 0;
1246 EBITSET_ELTS (bset
) = 0;
1247 ebitset_elts_grow (bset
, size
);
1254 ebitset_release_memory ()
1256 ebitset_free_list
= 0;
1257 if (ebitset_obstack_init
)
1259 ebitset_obstack_init
= 0;
1260 obstack_free (&ebitset_obstack
, NULL
);