1 /* Functions to support link list 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.
30 /* This file implements linked-list bitsets. These bitsets can be of
31 arbitrary length and are more efficient than arrays of bits for
34 Usually if all the bits in an element are zero we remove the element
35 from the list. However, a side effect of the bit caching is that we
36 do not always notice when an element becomes zero. Hence the
37 lbitset_weed function which removes zero elements. */
40 /* Number of words to use for each element. The larger the value the
41 greater the size of the cache and the shorter the time to find a given bit
42 but the more memory wasted for sparse bitsets and the longer the time
43 to search for set bits. */
45 #define LBITSET_ELT_WORDS 2
47 typedef bitset_word lbitset_word
;
49 #define LBITSET_WORD_BITS BITSET_WORD_BITS
51 /* Number of bits stored in each element. */
52 #define LBITSET_ELT_BITS \
53 ((unsigned) (LBITSET_ELT_WORDS * LBITSET_WORD_BITS))
55 /* Lbitset element. We use an array of bits for each element.
56 These are linked together in a doubly-linked list. */
57 typedef struct lbitset_elt_struct
59 struct lbitset_elt_struct
*next
; /* Next element. */
60 struct lbitset_elt_struct
*prev
; /* Previous element. */
61 bitset_windex index
; /* bitno / BITSET_WORD_BITS. */
62 bitset_word words
[LBITSET_ELT_WORDS
]; /* Bits that are set. */
67 enum lbitset_find_mode
68 { LBITSET_FIND
, LBITSET_CREATE
, LBITSET_SUBST
};
70 static lbitset_elt lbitset_zero_elts
[3]; /* Elements of all zero bits. */
72 /* Obstack to allocate bitset elements from. */
73 static struct obstack lbitset_obstack
;
74 static int lbitset_obstack_init
= 0;
75 static lbitset_elt
*lbitset_free_list
; /* Free list of bitset elements. */
77 extern void debug_lbitset
PARAMS ((bitset
));
79 #define LBITSET_CURRENT1(X) \
80 ((lbitset_elt *) (void *) ((char *) (X) - offsetof (lbitset_elt, words)))
82 #define LBITSET_CURRENT(X) LBITSET_CURRENT1((X)->b.cdata)
84 #define LBITSET_HEAD(X) ((X)->l.head)
85 #define LBITSET_TAIL(X) ((X)->l.tail)
87 /* Allocate a lbitset element. The bits are not cleared. */
88 static inline lbitset_elt
*
89 lbitset_elt_alloc (void)
93 if (lbitset_free_list
!= 0)
95 elt
= lbitset_free_list
;
96 lbitset_free_list
= elt
->next
;
100 if (!lbitset_obstack_init
)
102 lbitset_obstack_init
= 1;
104 /* Let particular systems override the size of a chunk. */
106 #ifndef OBSTACK_CHUNK_SIZE
107 #define OBSTACK_CHUNK_SIZE 0
110 /* Let them override the alloc and free routines too. */
112 #ifndef OBSTACK_CHUNK_ALLOC
113 #define OBSTACK_CHUNK_ALLOC xmalloc
116 #ifndef OBSTACK_CHUNK_FREE
117 #define OBSTACK_CHUNK_FREE free
120 #if !defined(__GNUC__) || (__GNUC__ < 2)
121 #define __alignof__(type) 0
124 obstack_specify_allocation (&lbitset_obstack
, OBSTACK_CHUNK_SIZE
,
125 __alignof__ (lbitset_elt
),
126 (void *(*)PARAMS ((long)))
128 (void (*)PARAMS ((void *)))
132 /* Perhaps we should add a number of new elements to the free
134 elt
= (lbitset_elt
*) obstack_alloc (&lbitset_obstack
,
135 sizeof (lbitset_elt
));
142 /* Allocate a lbitset element. The bits are cleared. */
143 static inline lbitset_elt
*
144 lbitset_elt_calloc (void)
148 elt
= lbitset_elt_alloc ();
149 memset (elt
->words
, 0, sizeof (elt
->words
));
155 lbitset_elt_free (lbitset_elt
*elt
)
157 elt
->next
= lbitset_free_list
;
158 lbitset_free_list
= elt
;
162 /* Unlink element ELT from bitset BSET. */
164 lbitset_elt_unlink (bitset bset
, lbitset_elt
*elt
)
166 lbitset_elt
*next
= elt
->next
;
167 lbitset_elt
*prev
= elt
->prev
;
175 if (LBITSET_HEAD (bset
) == elt
)
176 LBITSET_HEAD (bset
) = next
;
177 if (LBITSET_TAIL (bset
) == elt
)
178 LBITSET_TAIL (bset
) = prev
;
180 /* Update cache pointer. Since the first thing we try is to insert
181 before current, make current the next entry in preference to the
183 if (LBITSET_CURRENT (bset
) == elt
)
187 bset
->b
.cdata
= next
->words
;
188 bset
->b
.cindex
= next
->index
;
192 bset
->b
.cdata
= prev
->words
;
193 bset
->b
.cindex
= prev
->index
;
202 lbitset_elt_free (elt
);
206 /* Cut the chain of bitset BSET before element ELT and free the
209 lbitset_prune (bitset bset
, lbitset_elt
*elt
)
218 LBITSET_TAIL (bset
) = elt
->prev
;
219 bset
->b
.cdata
= elt
->prev
->words
;
220 bset
->b
.cindex
= elt
->prev
->index
;
225 LBITSET_HEAD (bset
) = 0;
226 LBITSET_TAIL (bset
) = 0;
231 for (; elt
; elt
= next
)
234 lbitset_elt_free (elt
);
239 /* Return nonzero if all bits in an element are zero. */
241 lbitset_elt_zero_p (lbitset_elt
*elt
)
245 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++)
253 /* Link the bitset element into the current bitset linked list. */
255 lbitset_elt_link (bitset bset
, lbitset_elt
*elt
)
257 bitset_windex windex
= elt
->index
;
259 lbitset_elt
*current
;
262 current
= LBITSET_CURRENT (bset
);
264 current
= LBITSET_HEAD (bset
);
266 /* If this is the first and only element, add it in. */
267 if (LBITSET_HEAD (bset
) == 0)
269 elt
->next
= elt
->prev
= 0;
270 LBITSET_HEAD (bset
) = elt
;
271 LBITSET_TAIL (bset
) = elt
;
274 /* If this index is less than that of the current element, it goes
275 somewhere before the current element. */
276 else if (windex
< bset
->b
.cindex
)
279 ptr
->prev
&& ptr
->prev
->index
> windex
; ptr
= ptr
->prev
)
283 ptr
->prev
->next
= elt
;
285 LBITSET_HEAD (bset
) = elt
;
287 elt
->prev
= ptr
->prev
;
292 /* Otherwise, it must go somewhere after the current element. */
296 ptr
->next
&& ptr
->next
->index
< windex
; ptr
= ptr
->next
)
300 ptr
->next
->prev
= elt
;
302 LBITSET_TAIL (bset
) = elt
;
304 elt
->next
= ptr
->next
;
309 /* Set up so this is the first element searched. */
310 bset
->b
.cindex
= windex
;
311 bset
->b
.csize
= LBITSET_ELT_WORDS
;
312 bset
->b
.cdata
= elt
->words
;
317 lbitset_elt_find (bitset bset
, bitset_windex windex
,
318 enum lbitset_find_mode mode
)
321 lbitset_elt
*current
;
325 current
= LBITSET_CURRENT (bset
);
326 /* Check if element is the cached element. */
327 if ((windex
- bset
->b
.cindex
) < bset
->b
.csize
)
332 current
= LBITSET_HEAD (bset
);
337 if (windex
< bset
->b
.cindex
)
340 elt
->prev
&& elt
->index
> windex
; elt
= elt
->prev
)
346 elt
->next
&& (elt
->index
+ LBITSET_ELT_WORDS
- 1) < windex
;
351 /* ELT is the nearest to the one we want. If it's not the one
352 we want, the one we want does not exist. */
353 if (elt
&& (windex
- elt
->index
) < LBITSET_ELT_WORDS
)
355 bset
->b
.cindex
= elt
->index
;
356 bset
->b
.csize
= LBITSET_ELT_WORDS
;
357 bset
->b
.cdata
= elt
->words
;
368 windex
-= windex
% LBITSET_ELT_WORDS
;
370 elt
= lbitset_elt_calloc ();
372 lbitset_elt_link (bset
, elt
);
376 return &lbitset_zero_elts
[0];
384 /* Weed out the zero elements from the list. */
386 lbitset_weed (bitset bset
)
391 for (elt
= LBITSET_HEAD (bset
); elt
; elt
= next
)
394 if (lbitset_elt_zero_p (elt
))
395 lbitset_elt_unlink (bset
, elt
);
400 /* Set all bits in the bitset to zero. */
402 lbitset_zero (bitset bset
)
406 head
= LBITSET_HEAD (bset
);
410 /* Clear a bitset by freeing the linked list at the head element. */
411 lbitset_prune (bset
, head
);
415 /* Return 1 if DST == SRC. */
417 lbitset_equal_p (bitset dst
, bitset src
)
428 for (selt
= LBITSET_HEAD (src
), delt
= LBITSET_HEAD (dst
);
429 selt
&& delt
; selt
= selt
->next
, delt
= delt
->next
)
431 if (selt
->index
!= delt
->index
)
434 for (j
= 0; j
< LBITSET_ELT_WORDS
; j
++)
435 if (delt
->words
[j
] != selt
->words
[j
])
438 return !selt
&& !delt
;
442 /* Copy bits from bitset SRC to bitset DST. */
444 lbitset_copy (bitset dst
, bitset src
)
456 head
= LBITSET_HEAD (src
);
461 for (elt
= head
; elt
; elt
= elt
->next
)
463 tmp
= lbitset_elt_alloc ();
464 tmp
->index
= elt
->index
;
470 LBITSET_HEAD (dst
) = tmp
;
473 memcpy (tmp
->words
, elt
->words
, sizeof (elt
->words
));
475 LBITSET_TAIL (dst
) = tmp
;
477 dst
->b
.csize
= LBITSET_ELT_WORDS
;
478 dst
->b
.cdata
= LBITSET_HEAD (dst
)->words
;
479 dst
->b
.cindex
= LBITSET_HEAD (dst
)->index
;
483 /* Copy bits from bitset SRC to bitset DST. Return non-zero if
484 bitsets different. */
486 lbitset_copy_cmp (bitset dst
, bitset src
)
491 if (!LBITSET_HEAD (dst
))
493 lbitset_copy (dst
, src
);
494 return LBITSET_HEAD (src
) != 0;
497 if (lbitset_equal_p (dst
, src
))
500 lbitset_copy (dst
, src
);
505 /* Return size in bits of bitset SRC. */
507 lbitset_size (bitset src
)
511 elt
= LBITSET_TAIL (src
);
515 /* Return current size of bitset in bits. */
516 return (elt
->index
+ LBITSET_ELT_WORDS
) * BITSET_WORD_BITS
;
520 /* Set bit BITNO in bitset DST. */
522 lbitset_set (bitset dst
, bitset_bindex bitno
)
524 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
526 lbitset_elt_find (dst
, windex
, LBITSET_CREATE
);
528 dst
->b
.cdata
[windex
- dst
->b
.cindex
] |=
529 (bitset_word
) 1 << (bitno
% BITSET_WORD_BITS
);
533 /* Reset bit BITNO in bitset DST. */
535 lbitset_reset (bitset dst
, bitset_bindex bitno
)
537 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
539 if (!lbitset_elt_find (dst
, windex
, LBITSET_FIND
))
542 dst
->b
.cdata
[windex
- dst
->b
.cindex
] &=
543 ~((bitset_word
) 1 << (bitno
% BITSET_WORD_BITS
));
545 /* If all the data is zero, perhaps we should unlink it now... */
549 /* Test bit BITNO in bitset SRC. */
551 lbitset_test (bitset src
, bitset_bindex bitno
)
553 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
555 if (!lbitset_elt_find (src
, windex
, LBITSET_FIND
))
558 return (src
->b
.cdata
[windex
- src
->b
.cindex
]
559 >> (bitno
% BITSET_WORD_BITS
)) & 1;
564 lbitset_free (bitset bset
)
570 /* Find list of up to NUM bits set in BSET starting from and including
571 *NEXT and store in array LIST. Return with actual number of bits
572 found and with *NEXT indicating where search stopped. */
574 lbitset_list_reverse (bitset bset
, bitset_bindex
*list
,
575 bitset_bindex num
, bitset_bindex
*next
)
577 bitset_bindex rbitno
;
580 bitset_bindex boffset
;
581 bitset_windex windex
;
585 bitset_bindex n_bits
;
587 elt
= LBITSET_TAIL (bset
);
591 n_bits
= (elt
->index
+ LBITSET_ELT_WORDS
) * BITSET_WORD_BITS
;
594 if (rbitno
>= n_bits
)
597 bitno
= n_bits
- (rbitno
+ 1);
599 windex
= bitno
/ BITSET_WORD_BITS
;
601 /* Skip back to starting element. */
602 for (; elt
&& elt
->index
> windex
; elt
= elt
->prev
)
608 if (windex
>= elt
->index
+ LBITSET_ELT_WORDS
)
610 /* We are trying to start in no-mans land so start
611 at end of current elt. */
612 bcount
= BITSET_WORD_BITS
- 1;
613 windex
= elt
->index
+ LBITSET_ELT_WORDS
- 1;
617 bcount
= bitno
% BITSET_WORD_BITS
;
621 boffset
= windex
* BITSET_WORD_BITS
;
623 /* If num is 1, we could speed things up with a binary search
624 of the word of interest. */
628 bitset_word
*srcp
= elt
->words
;
630 for (; (windex
- elt
->index
) < LBITSET_ELT_WORDS
;
631 windex
--, boffset
-= BITSET_WORD_BITS
,
632 bcount
= BITSET_WORD_BITS
- 1)
635 srcp
[windex
- elt
->index
] << (BITSET_WORD_BITS
- 1 - bcount
);
637 for (; word
; bcount
--)
639 if (word
& BITSET_MSB
)
641 list
[count
++] = boffset
+ bcount
;
644 *next
= n_bits
- (boffset
+ bcount
);
655 windex
= elt
->index
+ LBITSET_ELT_WORDS
- 1;
656 boffset
= windex
* BITSET_WORD_BITS
;
660 *next
= n_bits
- (boffset
+ 1);
665 /* Find list of up to NUM bits set in BSET starting from and including
666 *NEXT and store in array LIST. Return with actual number of bits
667 found and with *NEXT indicating where search stopped. */
669 lbitset_list (bitset bset
, bitset_bindex
*list
,
670 bitset_bindex num
, bitset_bindex
*next
)
673 bitset_windex windex
;
679 head
= LBITSET_HEAD (bset
);
688 /* This is the most common case. */
690 /* Start with the first element. */
693 bitno
= windex
* BITSET_WORD_BITS
;
697 windex
= bitno
/ BITSET_WORD_BITS
;
699 /* Skip to starting element. */
701 elt
&& (elt
->index
+ LBITSET_ELT_WORDS
- 1) < windex
;
708 if (windex
< elt
->index
)
711 bitno
= windex
* BITSET_WORD_BITS
;
715 bitset_word
*srcp
= elt
->words
;
717 /* We are starting within an element. */
719 for (; (windex
- elt
->index
) < LBITSET_ELT_WORDS
; windex
++)
721 word
= srcp
[windex
- elt
->index
] >> (bitno
% BITSET_WORD_BITS
);
723 for (; word
; bitno
++)
727 list
[count
++] = bitno
;
736 bitno
= (windex
+ 1) * BITSET_WORD_BITS
;
743 bitno
= windex
* BITSET_WORD_BITS
;
749 /* If num is 1, we could speed things up with a binary search
750 of the word of interest. */
755 bitset_word
*srcp
= elt
->words
;
757 if ((count
+ LBITSET_ELT_BITS
) < num
)
759 /* The coast is clear, plant boot! */
761 #if LBITSET_ELT_WORDS == 2
765 if (!(word
& 0xffff))
775 for (; word
; bitno
++)
778 list
[count
++] = bitno
;
783 bitno
= windex
* BITSET_WORD_BITS
;
788 if (!(word
& 0xffff))
793 for (; word
; bitno
++)
796 list
[count
++] = bitno
;
801 bitno
= windex
* BITSET_WORD_BITS
;
803 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++)
808 if (!(word
& 0xffff))
818 for (; word
; bitno
++)
821 list
[count
++] = bitno
;
826 bitno
= windex
* BITSET_WORD_BITS
;
832 /* Tread more carefully since we need to check
833 if array overflows. */
835 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++)
837 for (word
= srcp
[i
]; word
; bitno
++)
841 list
[count
++] = bitno
;
851 bitno
= windex
* BITSET_WORD_BITS
;
859 bitno
= windex
* BITSET_WORD_BITS
;
869 lbitset_empty_p (bitset dst
)
872 if (LBITSET_HEAD (dst
))
879 lbitset_ones (bitset dst
)
882 bitset_windex windex
;
885 /* This is a decidedly unfriendly operation for a linked list
886 bitset! It makes a sparse bitset become dense. An alternative
887 is to have a flag that indicates that the bitset stores the
888 complement of what it indicates. */
889 elt
= LBITSET_TAIL (dst
);
890 /* Ignore empty set. */
895 for (i
= 0; i
< windex
; i
+= LBITSET_ELT_WORDS
)
897 /* Create new elements if they cannot be found. */
898 elt
= lbitset_elt_find (dst
, i
, LBITSET_CREATE
);
899 memset (elt
->words
, -1, sizeof (elt
->words
));
905 lbitset_not (bitset dst
, bitset src
)
912 bitset_windex windex
;
914 /* This is another unfriendly operation for a linked list
916 elt
= LBITSET_TAIL (dst
);
917 /* Ignore empty set. */
922 for (i
= 0; i
< windex
; i
+= LBITSET_ELT_WORDS
)
924 /* Create new elements for dst if they cannot be found
925 or substitute zero elements if src elements not found. */
926 selt
= lbitset_elt_find (src
, i
, LBITSET_SUBST
);
927 delt
= lbitset_elt_find (dst
, i
, LBITSET_CREATE
);
929 for (j
= 0; j
< LBITSET_ELT_WORDS
; j
++)
930 delt
->words
[j
] = ~selt
->words
[j
];
937 /* Return 1 if DST == DST | SRC. */
939 lbitset_subset_p (bitset dst
, bitset src
)
945 for (selt
= LBITSET_HEAD (src
), delt
= LBITSET_HEAD (dst
);
946 selt
|| delt
; selt
= selt
->next
, delt
= delt
->next
)
949 selt
= &lbitset_zero_elts
[0];
951 delt
= &lbitset_zero_elts
[0];
952 else if (selt
->index
!= delt
->index
)
954 if (selt
->index
< delt
->index
)
956 lbitset_zero_elts
[2].next
= delt
;
957 delt
= &lbitset_zero_elts
[2];
961 lbitset_zero_elts
[1].next
= selt
;
962 selt
= &lbitset_zero_elts
[1];
966 for (j
= 0; j
< LBITSET_ELT_WORDS
; j
++)
967 if (delt
->words
[j
] != (selt
->words
[j
] | delt
->words
[j
]))
974 /* Return 1 if DST & SRC == 0. */
976 lbitset_disjoint_p (bitset dst
, bitset src
)
982 for (selt
= LBITSET_HEAD (src
), delt
= LBITSET_HEAD (dst
);
983 selt
&& delt
; selt
= selt
->next
, delt
= delt
->next
)
985 if (selt
->index
!= delt
->index
)
987 if (selt
->index
< delt
->index
)
989 lbitset_zero_elts
[2].next
= delt
;
990 delt
= &lbitset_zero_elts
[2];
994 lbitset_zero_elts
[1].next
= selt
;
995 selt
= &lbitset_zero_elts
[1];
997 /* Since the elements are different, there is no
998 intersection of these elements. */
1002 for (j
= 0; j
< LBITSET_ELT_WORDS
; j
++)
1003 if (selt
->words
[j
] & delt
->words
[j
])
1011 lbitset_op3_cmp (bitset dst
, bitset src1
, bitset src2
, enum bitset_ops op
)
1013 lbitset_elt
*selt1
= LBITSET_HEAD (src1
);
1014 lbitset_elt
*selt2
= LBITSET_HEAD (src2
);
1015 lbitset_elt
*delt
= LBITSET_HEAD (dst
);
1016 bitset_windex windex1
;
1017 bitset_windex windex2
;
1018 bitset_windex windex
;
1028 LBITSET_HEAD (dst
) = 0;
1031 windex1
= (selt1
) ? selt1
->index
: BITSET_WINDEX_MAX
;
1032 windex2
= (selt2
) ? selt2
->index
: BITSET_WINDEX_MAX
;
1034 while (selt1
|| selt2
)
1036 /* Figure out whether we need to substitute zero elements for
1038 if (windex1
== windex2
)
1043 selt1
= selt1
->next
;
1044 windex1
= (selt1
) ? selt1
->index
: BITSET_WINDEX_MAX
;
1045 selt2
= selt2
->next
;
1046 windex2
= (selt2
) ? selt2
->index
: BITSET_WINDEX_MAX
;
1048 else if (windex1
< windex2
)
1052 stmp2
= &lbitset_zero_elts
[0];
1053 selt1
= selt1
->next
;
1054 windex1
= (selt1
) ? selt1
->index
: BITSET_WINDEX_MAX
;
1059 stmp1
= &lbitset_zero_elts
[0];
1061 selt2
= selt2
->next
;
1062 windex2
= (selt2
) ? selt2
->index
: BITSET_WINDEX_MAX
;
1065 /* Find the appropriate element from DST. Begin by discarding
1066 elements that we've skipped. */
1067 while (delt
&& delt
->index
< windex
)
1072 lbitset_elt_free (dtmp
);
1074 if (delt
&& delt
->index
== windex
)
1080 dtmp
= lbitset_elt_calloc ();
1082 /* Do the operation, and if any bits are set, link it into the
1084 srcp1
= stmp1
->words
;
1085 srcp2
= stmp2
->words
;
1090 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1092 bitset_word tmp
= *srcp1
++ | *srcp2
++;
1103 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1105 bitset_word tmp
= *srcp1
++ & *srcp2
++;
1116 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1118 bitset_word tmp
= *srcp1
++ ^ *srcp2
++;
1128 case BITSET_OP_ANDN
:
1129 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1131 bitset_word tmp
= *srcp1
++ & ~(*srcp2
++);
1145 if (!lbitset_elt_zero_p (dtmp
))
1147 dtmp
->index
= windex
;
1148 /* Perhaps this could be optimised... */
1149 lbitset_elt_link (dst
, dtmp
);
1153 lbitset_elt_free (dtmp
);
1157 /* If we have elements of DST left over, free them all. */
1161 lbitset_prune (dst
, delt
);
1169 lbitset_and_cmp (bitset dst
, bitset src1
, bitset src2
)
1171 lbitset_elt
*selt1
= LBITSET_HEAD (src1
);
1172 lbitset_elt
*selt2
= LBITSET_HEAD (src2
);
1178 changed
= !LBITSET_HEAD (dst
);
1185 changed
= !LBITSET_HEAD (dst
);
1189 return lbitset_op3_cmp (dst
, src1
, src2
, BITSET_OP_AND
);
1194 lbitset_and (bitset dst
, bitset src1
, bitset src2
)
1196 lbitset_and_cmp (dst
, src1
, src2
);
1201 lbitset_andn_cmp (bitset dst
, bitset src1
, bitset src2
)
1203 lbitset_elt
*selt1
= LBITSET_HEAD (src1
);
1204 lbitset_elt
*selt2
= LBITSET_HEAD (src2
);
1209 return lbitset_copy_cmp (dst
, src1
);
1214 changed
= !LBITSET_HEAD (dst
);
1218 return lbitset_op3_cmp (dst
, src1
, src2
, BITSET_OP_ANDN
);
1223 lbitset_andn (bitset dst
, bitset src1
, bitset src2
)
1225 lbitset_andn_cmp (dst
, src1
, src2
);
1230 lbitset_or_cmp (bitset dst
, bitset src1
, bitset src2
)
1232 lbitset_elt
*selt1
= LBITSET_HEAD (src1
);
1233 lbitset_elt
*selt2
= LBITSET_HEAD (src2
);
1237 return lbitset_copy_cmp (dst
, src1
);
1241 return lbitset_copy_cmp (dst
, src2
);
1243 return lbitset_op3_cmp (dst
, src1
, src2
, BITSET_OP_OR
);
1248 lbitset_or (bitset dst
, bitset src1
, bitset src2
)
1250 lbitset_or_cmp (dst
, src1
, src2
);
1255 lbitset_xor_cmp (bitset dst
, bitset src1
, bitset src2
)
1257 lbitset_elt
*selt1
= LBITSET_HEAD (src1
);
1258 lbitset_elt
*selt2
= LBITSET_HEAD (src2
);
1262 return lbitset_copy_cmp (dst
, src1
);
1266 return lbitset_copy_cmp (dst
, src2
);
1268 return lbitset_op3_cmp (dst
, src1
, src2
, BITSET_OP_XOR
);
1273 lbitset_xor (bitset dst
, bitset src1
, bitset src2
)
1275 lbitset_xor_cmp (dst
, src1
, src2
);
1280 /* Vector of operations for linked-list bitsets. */
1281 struct bitset_vtable lbitset_vtable
= {
1307 bitset_andn_or_cmp_
,
1311 lbitset_list_reverse
,
1317 /* Return size of initial structure. */
1319 lbitset_bytes (bitset_bindex n_bits ATTRIBUTE_UNUSED
)
1321 return sizeof (struct lbitset_struct
);
1325 /* Initialize a bitset. */
1327 lbitset_init (bitset bset
, bitset_bindex n_bits ATTRIBUTE_UNUSED
)
1329 bset
->b
.vtable
= &lbitset_vtable
;
1335 lbitset_release_memory (void)
1337 lbitset_free_list
= 0;
1338 if (lbitset_obstack_init
)
1340 lbitset_obstack_init
= 0;
1341 obstack_free (&lbitset_obstack
, NULL
);
1346 /* Function to be called from debugger to debug lbitset. */
1348 debug_lbitset (bitset bset
)
1356 for (elt
= LBITSET_HEAD (bset
); elt
; elt
= elt
->next
)
1358 fprintf (stderr
, "Elt %lu\n", (unsigned long) elt
->index
);
1359 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++)
1364 word
= elt
->words
[i
];
1366 fprintf (stderr
, " Word %u:", i
);
1367 for (j
= 0; j
< LBITSET_WORD_BITS
; j
++)
1368 if ((word
& ((bitset_word
) 1 << j
)))
1369 fprintf (stderr
, " %u", j
);
1370 fprintf (stderr
, "\n");