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.
28 /* This file implements linked-list bitsets. These bitsets can be of
29 arbitrary length and are more efficient than arrays of bits for
32 Usually if all the bits in an element are zero we remove the element
33 from the list. However, a side effect of the bit caching is that we
34 do not always notice when an element becomes zero. Hence the
35 lbitset_weed function which removes zero elements. */
38 /* Number of words to use for each element. The larger the value the
39 greater the size of the cache and the shorter the time to find a given bit
40 but the more memory wasted for sparse bitsets and the longer the time
41 to search for set bits. */
43 #define LBITSET_ELT_WORDS 2
45 typedef bitset_word lbitset_word
;
47 #define LBITSET_WORD_BITS BITSET_WORD_BITS
49 /* Number of bits stored in each element. */
50 #define LBITSET_ELT_BITS \
51 ((unsigned) (LBITSET_ELT_WORDS * LBITSET_WORD_BITS))
53 /* Lbitset element. We use an array of bits for each element.
54 These are linked together in a doubly-linked list. */
55 typedef struct lbitset_elt_struct
57 struct lbitset_elt_struct
*next
; /* Next element. */
58 struct lbitset_elt_struct
*prev
; /* Previous element. */
59 bitset_windex index
; /* bitno / BITSET_WORD_BITS. */
60 bitset_word words
[LBITSET_ELT_WORDS
]; /* Bits that are set. */
65 /* Head of lbitset linked list. */
66 typedef struct lbitset_struct
68 lbitset_elt
*head
; /* First element in linked list. */
69 lbitset_elt
*tail
; /* Last element in linked list. */
76 struct bbitset_struct b
;
77 struct lbitset_struct l
;
81 enum lbitset_find_mode
82 { LBITSET_FIND
, LBITSET_CREATE
, LBITSET_SUBST
};
84 static lbitset_elt lbitset_zero_elts
[3]; /* Elements of all zero bits. */
86 /* Obstack to allocate bitset elements from. */
87 static struct obstack lbitset_obstack
;
88 static int lbitset_obstack_init
= 0;
89 static lbitset_elt
*lbitset_free_list
; /* Free list of bitset elements. */
91 static lbitset_elt
*lbitset_elt_alloc
PARAMS ((void));
92 static lbitset_elt
*lbitset_elt_calloc
PARAMS ((void));
93 static void lbitset_elt_link
PARAMS ((bitset
, lbitset_elt
*));
94 static void lbitset_elt_unlink
PARAMS ((bitset
, lbitset_elt
*));
95 static void lbitset_elt_free
PARAMS ((lbitset_elt
*));
96 static lbitset_elt
*lbitset_elt_find
PARAMS ((bitset
, bitset_windex
,
97 enum lbitset_find_mode
));
98 static int lbitset_elt_zero_p
PARAMS ((lbitset_elt
*));
100 static void lbitset_prune
PARAMS ((bitset
, lbitset_elt
*));
101 static void lbitset_weed
PARAMS ((bitset
));
102 static void lbitset_zero
PARAMS ((bitset
));
103 static int lbitset_equal_p
PARAMS ((bitset
, bitset
));
104 static void lbitset_copy
PARAMS ((bitset
, bitset
));
105 static int lbitset_copy_compare
PARAMS ((bitset
, bitset
));
106 static void lbitset_set
PARAMS ((bitset
, bitset_bindex
));
107 static void lbitset_reset
PARAMS ((bitset
, bitset_bindex
));
108 static int lbitset_test
PARAMS ((bitset
, bitset_bindex
));
109 static int lbitset_size
PARAMS ((bitset
));
110 static int lbitset_op1
PARAMS ((bitset
, enum bitset_ops
));
111 static int lbitset_op2
PARAMS ((bitset
, bitset
, enum bitset_ops
));
112 static int lbitset_op3
PARAMS ((bitset
, bitset
, bitset
, enum bitset_ops
));
113 static int lbitset_list
PARAMS ((bitset
, bitset_bindex
*, bitset_bindex
,
115 static int lbitset_reverse_list
116 PARAMS ((bitset
, bitset_bindex
*, bitset_bindex
, bitset_bindex
*));
117 static void lbitset_free
PARAMS ((bitset
));
120 #define LBITSET_CURRENT1(X) (lbitset_elt *)((char *)(X) + ((char *)&(((lbitset_elt *)(X))->next) - (char *)&(((lbitset_elt *)(X))->words)))
122 #define LBITSET_CURRENT(X) LBITSET_CURRENT1((X)->b.cdata)
124 #define LBITSET_HEAD(X) ((X)->l.head)
125 #define LBITSET_TAIL(X) ((X)->l.tail)
127 /* Allocate a lbitset element. The bits are not cleared. */
128 static inline lbitset_elt
*
133 if (lbitset_free_list
!= 0)
135 elt
= lbitset_free_list
;
136 lbitset_free_list
= elt
->next
;
140 if (!lbitset_obstack_init
)
142 lbitset_obstack_init
= 1;
144 /* Let particular systems override the size of a chunk. */
146 #ifndef OBSTACK_CHUNK_SIZE
147 #define OBSTACK_CHUNK_SIZE 0
150 /* Let them override the alloc and free routines too. */
152 #ifndef OBSTACK_CHUNK_ALLOC
153 #define OBSTACK_CHUNK_ALLOC xmalloc
156 #ifndef OBSTACK_CHUNK_FREE
157 #define OBSTACK_CHUNK_FREE free
160 #if !defined(__GNUC__) || (__GNUC__ < 2)
161 #define __alignof__(type) 0
164 obstack_specify_allocation (&lbitset_obstack
, OBSTACK_CHUNK_SIZE
,
165 __alignof__ (lbitset_elt
),
166 (void *(*)PARAMS ((long)))
168 (void (*)PARAMS ((void *)))
172 /* Perhaps we should add a number of new elements to the free
174 elt
= (lbitset_elt
*) obstack_alloc (&lbitset_obstack
,
175 sizeof (lbitset_elt
));
182 /* Allocate a lbitset element. The bits are cleared. */
183 static inline lbitset_elt
*
184 lbitset_elt_calloc ()
188 elt
= lbitset_elt_alloc ();
189 memset (elt
->words
, 0, sizeof (elt
->words
));
195 lbitset_elt_free (elt
)
198 elt
->next
= lbitset_free_list
;
199 lbitset_free_list
= elt
;
203 /* Unlink element ELT from bitset BSET. */
205 lbitset_elt_unlink (bset
, elt
)
209 lbitset_elt
*next
= elt
->next
;
210 lbitset_elt
*prev
= elt
->prev
;
218 if (LBITSET_HEAD (bset
) == elt
)
219 LBITSET_HEAD (bset
) = next
;
220 if (LBITSET_TAIL (bset
) == elt
)
221 LBITSET_TAIL (bset
) = prev
;
223 /* Update cache pointer. Since the first thing we try is to insert
224 before current, make current the next entry in preference to the
226 if (LBITSET_CURRENT (bset
) == elt
)
230 bset
->b
.cdata
= next
->words
;
231 bset
->b
.cindex
= next
->index
;
235 bset
->b
.cdata
= prev
->words
;
236 bset
->b
.cindex
= prev
->index
;
245 lbitset_elt_free (elt
);
249 /* Cut the chain of bitset BSET before element ELT and free the
252 lbitset_prune (bset
, elt
)
263 LBITSET_TAIL (bset
) = elt
->prev
;
264 bset
->b
.cdata
= elt
->prev
->words
;
265 bset
->b
.cindex
= elt
->prev
->index
;
270 LBITSET_HEAD (bset
) = 0;
271 LBITSET_TAIL (bset
) = 0;
276 for (; elt
; elt
= next
)
279 lbitset_elt_free (elt
);
284 /* Return nonzero if all bits in an element are zero. */
286 lbitset_elt_zero_p (elt
)
291 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++)
299 /* Link the bitset element into the current bitset linked list. */
301 lbitset_elt_link (bset
, elt
)
305 bitset_windex windex
= elt
->index
;
307 lbitset_elt
*current
;
310 current
= LBITSET_CURRENT (bset
);
312 current
= LBITSET_HEAD (bset
);
314 /* If this is the first and only element, add it in. */
315 if (LBITSET_HEAD (bset
) == 0)
317 elt
->next
= elt
->prev
= 0;
318 LBITSET_HEAD (bset
) = elt
;
319 LBITSET_TAIL (bset
) = elt
;
322 /* If this index is less than that of the current element, it goes
323 somewhere before the current element. */
324 else if (windex
< bset
->b
.cindex
)
327 ptr
->prev
&& ptr
->prev
->index
> windex
; ptr
= ptr
->prev
)
331 ptr
->prev
->next
= elt
;
333 LBITSET_HEAD (bset
) = elt
;
335 elt
->prev
= ptr
->prev
;
340 /* Otherwise, it must go somewhere after the current element. */
344 ptr
->next
&& ptr
->next
->index
< windex
; ptr
= ptr
->next
)
348 ptr
->next
->prev
= elt
;
350 LBITSET_TAIL (bset
) = elt
;
352 elt
->next
= ptr
->next
;
357 /* Set up so this is the first element searched. */
358 bset
->b
.cindex
= windex
;
359 bset
->b
.csize
= LBITSET_ELT_WORDS
;
360 bset
->b
.cdata
= elt
->words
;
365 lbitset_elt_find (bset
, windex
, mode
)
367 bitset_windex windex
;
368 enum lbitset_find_mode mode
;
371 lbitset_elt
*current
;
375 current
= LBITSET_CURRENT (bset
);
376 /* Check if element is the cached element. */
377 if ((windex
- bset
->b
.cindex
) < bset
->b
.csize
)
382 current
= LBITSET_HEAD (bset
);
387 if (windex
< bset
->b
.cindex
)
390 elt
->prev
&& elt
->index
> windex
; elt
= elt
->prev
)
396 elt
->next
&& (elt
->index
+ LBITSET_ELT_WORDS
- 1) < windex
;
401 /* `element' is the nearest to the one we want. If it's not the one
402 we want, the one we want does not exist. */
403 if (elt
&& (windex
- elt
->index
) < LBITSET_ELT_WORDS
)
405 bset
->b
.cindex
= elt
->index
;
406 bset
->b
.csize
= LBITSET_ELT_WORDS
;
407 bset
->b
.cdata
= elt
->words
;
418 windex
= (windex
/ (unsigned) LBITSET_ELT_WORDS
) * LBITSET_ELT_WORDS
;
420 elt
= lbitset_elt_calloc ();
422 lbitset_elt_link (bset
, elt
);
426 return &lbitset_zero_elts
[0];
434 /* Weed out the zero elements from the list. */
442 for (elt
= LBITSET_HEAD (bset
); elt
; elt
= next
)
445 if (lbitset_elt_zero_p (elt
))
446 lbitset_elt_unlink (bset
, elt
);
451 /* Set all bits in the bitset to zero. */
458 head
= LBITSET_HEAD (bset
);
462 /* Clear a bitset by freeing the linked list at the head element. */
463 lbitset_prune (bset
, head
);
468 lbitset_equal_p (dst
, src
)
481 for (selt
= LBITSET_HEAD (src
), delt
= LBITSET_HEAD (dst
);
482 selt
&& delt
; selt
= selt
->next
, delt
= delt
->next
)
484 if (selt
->index
!= delt
->index
)
487 for (j
= 0; j
< LBITSET_ELT_WORDS
; j
++)
488 if (delt
->words
[j
] != selt
->words
[j
])
491 return !selt
&& !delt
;
495 /* Copy bits from bitset SRC to bitset DST. */
497 lbitset_copy (dst
, src
)
511 head
= LBITSET_HEAD (src
);
516 for (elt
= head
; elt
; elt
= elt
->next
)
518 tmp
= lbitset_elt_alloc ();
519 tmp
->index
= elt
->index
;
525 LBITSET_HEAD (dst
) = tmp
;
528 memcpy (tmp
->words
, elt
->words
, sizeof (elt
->words
));
530 LBITSET_TAIL (dst
) = tmp
;
532 dst
->b
.csize
= LBITSET_ELT_WORDS
;
533 dst
->b
.cdata
= LBITSET_HEAD (dst
)->words
;
534 dst
->b
.cindex
= LBITSET_HEAD (dst
)->index
;
538 /* Copy bits from bitset SRC to bitset DST. Return non-zero if
539 bitsets different. */
541 lbitset_copy_compare (dst
, src
)
548 if (!LBITSET_HEAD (dst
))
550 lbitset_copy (dst
, src
);
551 return LBITSET_HEAD (src
) != 0;
554 if (lbitset_equal_p (dst
, src
))
557 lbitset_copy (dst
, src
);
562 /* Return size in bits of bitset SRC. */
569 elt
= LBITSET_TAIL (src
);
573 /* Return current size of bitset in bits. */
574 return (elt
->index
+ LBITSET_ELT_WORDS
) * BITSET_WORD_BITS
;
578 /* Set bit BITNO in bitset DST. */
580 lbitset_set (dst
, bitno
)
584 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
586 lbitset_elt_find (dst
, windex
, LBITSET_CREATE
);
588 dst
->b
.cdata
[windex
- dst
->b
.cindex
] |=
589 (bitset_word
) 1 << (bitno
% BITSET_WORD_BITS
);
593 /* Reset bit BITNO in bitset DST. */
595 lbitset_reset (dst
, bitno
)
599 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
601 if (!lbitset_elt_find (dst
, windex
, LBITSET_FIND
))
604 dst
->b
.cdata
[windex
- dst
->b
.cindex
] &=
605 ~((bitset_word
) 1 << (bitno
% BITSET_WORD_BITS
));
607 /* If all the data is zero, perhaps we should unlink it now... */
611 /* Test bit BITNO in bitset SRC. */
613 lbitset_test (src
, bitno
)
617 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
619 if (!lbitset_elt_find (src
, windex
, LBITSET_FIND
))
622 return (src
->b
.cdata
[windex
- src
->b
.cindex
]
623 >> (bitno
% BITSET_WORD_BITS
)) & 1;
635 /* Find list of up to NUM bits set in BSET starting from and including
636 *NEXT and store in array LIST. Return with actual number of bits
637 found and with *NEXT indicating where search stopped. */
639 lbitset_reverse_list (bset
, list
, num
, next
)
645 bitset_bindex rbitno
;
648 bitset_bindex boffset
;
649 bitset_windex windex
;
653 bitset_bindex n_bits
;
655 elt
= LBITSET_TAIL (bset
);
659 n_bits
= (elt
->index
+ LBITSET_ELT_WORDS
) * BITSET_WORD_BITS
;
662 if (rbitno
>= n_bits
)
665 bitno
= n_bits
- (rbitno
+ 1);
667 windex
= bitno
/ BITSET_WORD_BITS
;
669 /* Skip back to starting element. */
670 for (; elt
&& elt
->index
> windex
; elt
= elt
->prev
)
676 /* If num is 1, we could speed things up with a binary search
677 of the word of interest. */
680 bcount
= bitno
% BITSET_WORD_BITS
;
681 boffset
= windex
* BITSET_WORD_BITS
;
685 bitset_word
*srcp
= elt
->words
;
687 for (; (windex
- elt
->index
) < LBITSET_ELT_WORDS
;
688 windex
--, boffset
-= BITSET_WORD_BITS
,
689 bcount
= BITSET_WORD_BITS
- 1)
692 srcp
[windex
- elt
->index
] << (BITSET_WORD_BITS
- 1 - bcount
);
694 for (; word
; bcount
--)
696 if (word
& BITSET_MSB
)
698 list
[count
++] = boffset
+ bcount
;
701 *next
= n_bits
- (boffset
+ bcount
);
712 windex
= elt
->index
+ LBITSET_ELT_WORDS
- 1;
713 boffset
= windex
* BITSET_WORD_BITS
;
717 *next
= n_bits
- (boffset
+ 1);
722 /* Find list of up to NUM bits set in BSET starting from and including
723 *NEXT and store in array LIST. Return with actual number of bits
724 found and with *NEXT indicating where search stopped. */
726 lbitset_list (bset
, list
, num
, next
)
733 bitset_windex windex
;
739 head
= LBITSET_HEAD (bset
);
748 /* This is the most common case. */
750 /* Start with the first element. */
753 bitno
= windex
* BITSET_WORD_BITS
;
757 windex
= bitno
/ BITSET_WORD_BITS
;
759 /* Skip to starting element. */
761 elt
&& (elt
->index
+ LBITSET_ELT_WORDS
- 1) < windex
;
768 if (windex
< elt
->index
)
771 bitno
= windex
* BITSET_WORD_BITS
;
775 bitset_word
*srcp
= elt
->words
;
777 /* We are starting within an element. */
779 for (; (windex
- elt
->index
) < LBITSET_ELT_WORDS
; windex
++)
781 word
= srcp
[windex
- elt
->index
] >> (bitno
% BITSET_WORD_BITS
);
783 for (; word
; bitno
++)
787 list
[count
++] = bitno
;
796 bitno
= (windex
+ 1) * BITSET_WORD_BITS
;
803 bitno
= windex
* BITSET_WORD_BITS
;
809 /* If num is 1, we could speed things up with a binary search
810 of the word of interest. */
815 bitset_word
*srcp
= elt
->words
;
817 if ((count
+ LBITSET_ELT_BITS
) < num
)
819 /* The coast is clear, plant boot! */
821 #if LBITSET_ELT_WORDS == 2
825 if (!(word
& 0xffff))
835 for (; word
; bitno
++)
838 list
[count
++] = bitno
;
843 bitno
= windex
* BITSET_WORD_BITS
;
848 if (!(word
& 0xffff))
853 for (; word
; bitno
++)
856 list
[count
++] = bitno
;
861 bitno
= windex
* BITSET_WORD_BITS
;
863 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++)
868 if (!(word
& 0xffff))
878 for (; word
; bitno
++)
881 list
[count
++] = bitno
;
886 bitno
= windex
* BITSET_WORD_BITS
;
892 /* Tread more carefully since we need to check
893 if array overflows. */
895 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++)
897 for (word
= srcp
[i
]; word
; bitno
++)
901 list
[count
++] = bitno
;
911 bitno
= windex
* BITSET_WORD_BITS
;
919 bitno
= windex
* BITSET_WORD_BITS
;
929 lbitset_op1 (dst
, op
)
934 bitset_windex windex
;
944 /* This is a decidedly unfriendly operation for a linked list
946 elt
= LBITSET_TAIL (dst
);
947 /* Ignore empty set. */
952 for (i
= 0; i
< windex
; i
+= LBITSET_ELT_WORDS
)
954 /* Create new elements if they cannot be found. */
955 elt
= lbitset_elt_find (dst
, i
, LBITSET_CREATE
);
956 memset (elt
->words
, -1, sizeof (elt
->words
));
960 case BITSET_OP_EMPTY_P
:
962 if (LBITSET_HEAD (dst
))
975 lbitset_op2 (dst
, src
, op
)
985 bitset_windex windex
;
990 lbitset_copy (dst
, src
);
994 /* This is another unfriendly operation for a linked list
996 elt
= LBITSET_TAIL (dst
);
997 /* Ignore empty set. */
1001 windex
= elt
->index
;
1002 for (i
= 0; i
< windex
; i
+= LBITSET_ELT_WORDS
)
1004 /* Create new elements for dst if they cannot be found
1005 or substitute zero elements if src elements not found. */
1006 selt
= lbitset_elt_find (dst
, i
, LBITSET_SUBST
);
1007 delt
= lbitset_elt_find (dst
, i
, LBITSET_CREATE
);
1009 for (j
= 0; j
< LBITSET_ELT_WORDS
; j
++)
1010 delt
->words
[j
] = ~selt
->words
[j
];
1015 /* Return 1 if DST == SRC. */
1016 case BITSET_OP_EQUAL_P
:
1017 return lbitset_equal_p (dst
, src
);
1020 /* Return 1 if DST == DST | SRC. */
1021 case BITSET_OP_SUBSET_P
:
1022 for (selt
= LBITSET_HEAD (src
), delt
= LBITSET_HEAD (dst
);
1023 selt
|| delt
; selt
= selt
->next
, delt
= delt
->next
)
1026 selt
= &lbitset_zero_elts
[0];
1028 delt
= &lbitset_zero_elts
[0];
1029 else if (selt
->index
!= delt
->index
)
1031 if (selt
->index
< delt
->index
)
1033 lbitset_zero_elts
[2].next
= delt
;
1034 delt
= &lbitset_zero_elts
[2];
1038 lbitset_zero_elts
[1].next
= selt
;
1039 selt
= &lbitset_zero_elts
[1];
1043 for (j
= 0; j
< LBITSET_ELT_WORDS
; j
++)
1044 if (delt
->words
[j
] != (selt
->words
[j
] | delt
->words
[j
]))
1049 /* Return 1 if DST & SRC == 0. */
1050 case BITSET_OP_DISJOINT_P
:
1051 for (selt
= LBITSET_HEAD (src
), delt
= LBITSET_HEAD (dst
);
1052 selt
&& delt
; selt
= selt
->next
, delt
= delt
->next
)
1054 if (selt
->index
!= delt
->index
)
1056 if (selt
->index
< delt
->index
)
1058 lbitset_zero_elts
[2].next
= delt
;
1059 delt
= &lbitset_zero_elts
[2];
1063 lbitset_zero_elts
[1].next
= selt
;
1064 selt
= &lbitset_zero_elts
[1];
1066 /* Since the elements are different, there is no
1067 intersection of these elements. */
1071 for (j
= 0; j
< LBITSET_ELT_WORDS
; j
++)
1072 if (selt
->words
[j
] & delt
->words
[j
])
1086 lbitset_op3 (dst
, src1
, src2
, op
)
1092 lbitset_elt
*selt1
= LBITSET_HEAD (src1
);
1093 lbitset_elt
*selt2
= LBITSET_HEAD (src2
);
1094 lbitset_elt
*delt
= LBITSET_HEAD (dst
);
1095 bitset_windex windex1
;
1096 bitset_windex windex2
;
1097 bitset_windex windex
;
1107 /* Fast track common, simple cases. */
1110 if (op
== BITSET_OP_AND
)
1113 changed
= !LBITSET_HEAD (dst
);
1117 else if (op
== BITSET_OP_ANDN
|| op
== BITSET_OP_OR
1118 || op
== BITSET_OP_XOR
)
1120 return lbitset_copy_compare (dst
, src1
);
1125 if (op
== BITSET_OP_AND
|| op
== BITSET_OP_ANDN
)
1128 changed
= !LBITSET_HEAD (dst
);
1132 else if (op
== BITSET_OP_OR
|| op
== BITSET_OP_XOR
)
1134 return lbitset_copy_compare (dst
, src2
);
1138 LBITSET_HEAD (dst
) = 0;
1141 windex1
= (selt1
) ? selt1
->index
: BITSET_INDEX_MAX
;
1142 windex2
= (selt2
) ? selt2
->index
: BITSET_INDEX_MAX
;
1144 while (selt1
|| selt2
)
1146 /* Figure out whether we need to substitute zero elements for
1148 if (windex1
== windex2
)
1153 selt1
= selt1
->next
;
1154 windex1
= (selt1
) ? selt1
->index
: BITSET_INDEX_MAX
;
1155 selt2
= selt2
->next
;
1156 windex2
= (selt2
) ? selt2
->index
: BITSET_INDEX_MAX
;
1158 else if (windex1
< windex2
)
1162 stmp2
= &lbitset_zero_elts
[0];
1163 selt1
= selt1
->next
;
1164 windex1
= (selt1
) ? selt1
->index
: BITSET_INDEX_MAX
;
1169 stmp1
= &lbitset_zero_elts
[0];
1171 selt2
= selt2
->next
;
1172 windex2
= (selt2
) ? selt2
->index
: BITSET_INDEX_MAX
;
1175 /* Find the appropriate element from DST. Begin by discarding
1176 elements that we've skipped. */
1177 while (delt
&& delt
->index
< windex
)
1182 lbitset_elt_free (dtmp
);
1184 if (delt
&& delt
->index
== windex
)
1190 dtmp
= lbitset_elt_calloc ();
1192 /* Do the operation, and if any bits are set, link it into the
1194 srcp1
= stmp1
->words
;
1195 srcp2
= stmp2
->words
;
1200 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1202 bitset_word tmp
= *srcp1
++ | *srcp2
++;
1213 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1215 bitset_word tmp
= *srcp1
++ & *srcp2
++;
1226 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1228 bitset_word tmp
= *srcp1
++ ^ *srcp2
++;
1238 case BITSET_OP_ANDN
:
1239 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1241 bitset_word tmp
= *srcp1
++ & ~(*srcp2
++);
1255 if (!lbitset_elt_zero_p (dtmp
))
1257 dtmp
->index
= windex
;
1258 /* Perhaps this could be optimised... */
1259 lbitset_elt_link (dst
, dtmp
);
1263 lbitset_elt_free (dtmp
);
1267 /* If we have elements of DST left over, free them all. */
1271 lbitset_prune (dst
, delt
);
1278 /* Vector of operations for linked-list bitsets. */
1279 struct bitset_ops_struct lbitset_ops
= {
1289 lbitset_reverse_list
,
1295 /* Return size of initial structure. */
1297 lbitset_bytes (n_bits
)
1298 bitset_bindex n_bits ATTRIBUTE_UNUSED
;
1300 return sizeof (struct bitset_struct
);
1304 /* Initialize a bitset. */
1307 lbitset_init (bset
, n_bits
)
1309 bitset_bindex n_bits ATTRIBUTE_UNUSED
;
1311 bset
->b
.ops
= &lbitset_ops
;
1317 lbitset_release_memory ()
1319 lbitset_free_list
= 0;
1320 if (lbitset_obstack_init
)
1322 lbitset_obstack_init
= 0;
1323 obstack_free (&lbitset_obstack
, NULL
);