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.
29 /* This file implements linked-list bitsets. These bitsets can be of
30 arbitrary length and are more efficient than arrays of bits for
33 Usually if all the bits in an element are zero we remove the element
34 from the list. However, a side effect of the bit caching is that we
35 do not always notice when an element becomes zero. Hence the
36 lbitset_weed function which removes zero elements. */
39 /* Number of words to use for each element. The larger the value the
40 greater the size of the cache and the shorter the time to find a given bit
41 but the more memory wasted for sparse bitsets and the longer the time
42 to search for set bits. */
44 #define LBITSET_ELT_WORDS 2
46 typedef bitset_word lbitset_word
;
48 #define LBITSET_WORD_BITS BITSET_WORD_BITS
50 /* Number of bits stored in each element. */
51 #define LBITSET_ELT_BITS \
52 ((unsigned) (LBITSET_ELT_WORDS * LBITSET_WORD_BITS))
54 /* Lbitset element. We use an array of bits for each element.
55 These are linked together in a doubly-linked list. */
56 typedef struct lbitset_elt_struct
58 struct lbitset_elt_struct
*next
; /* Next element. */
59 struct lbitset_elt_struct
*prev
; /* Previous element. */
60 bitset_windex index
; /* bitno / BITSET_WORD_BITS. */
61 bitset_word words
[LBITSET_ELT_WORDS
]; /* Bits that are set. */
66 /* Head of lbitset linked list. */
67 typedef struct lbitset_struct
69 lbitset_elt
*head
; /* First element in linked list. */
70 lbitset_elt
*tail
; /* Last element in linked list. */
77 struct bbitset_struct b
;
78 struct lbitset_struct l
;
85 enum lbitset_find_mode
86 { LBITSET_FIND
, LBITSET_CREATE
, LBITSET_SUBST
};
88 static lbitset_elt lbitset_zero_elts
[3]; /* Elements of all zero bits. */
90 /* Obstack to allocate bitset elements from. */
91 static struct obstack lbitset_obstack
;
92 static int lbitset_obstack_init
= 0;
93 static lbitset_elt
*lbitset_free_list
; /* Free list of bitset elements. */
95 static lbitset_elt
*lbitset_elt_alloc
PARAMS ((void));
96 static lbitset_elt
*lbitset_elt_calloc
PARAMS ((void));
97 static void lbitset_elt_link
PARAMS ((bitset
, lbitset_elt
*));
98 static void lbitset_elt_unlink
PARAMS ((bitset
, lbitset_elt
*));
99 static void lbitset_elt_free
PARAMS ((lbitset_elt
*));
100 static lbitset_elt
*lbitset_elt_find
PARAMS ((bitset
, bitset_windex
,
101 enum lbitset_find_mode
));
102 static int lbitset_elt_zero_p
PARAMS ((lbitset_elt
*));
104 static void lbitset_prune
PARAMS ((bitset
, lbitset_elt
*));
105 static void lbitset_weed
PARAMS ((bitset
));
106 static void lbitset_zero
PARAMS ((bitset
));
107 static int lbitset_equal_p
PARAMS ((bitset
, bitset
));
108 static void lbitset_copy
PARAMS ((bitset
, bitset
));
109 static int lbitset_copy_cmp
PARAMS ((bitset
, bitset
));
110 static void lbitset_set
PARAMS ((bitset
, bitset_bindex
));
111 static void lbitset_reset
PARAMS ((bitset
, bitset_bindex
));
112 static int lbitset_test
PARAMS ((bitset
, bitset_bindex
));
113 static bitset_bindex lbitset_size
PARAMS ((bitset
));
114 static int lbitset_op3_cmp
PARAMS ((bitset
, bitset
, bitset
, enum bitset_ops
));
115 static bitset_bindex lbitset_list
PARAMS ((bitset
, bitset_bindex
*,
116 bitset_bindex
, bitset_bindex
*));
117 static bitset_bindex lbitset_list_reverse
118 PARAMS ((bitset
, bitset_bindex
*, bitset_bindex
, bitset_bindex
*));
119 static void lbitset_free
PARAMS ((bitset
));
122 #define LBITSET_CURRENT1(X) (lbitset_elt *)((char *)(X) + ((char *)&(((lbitset_elt *)(X))->next) - (char *)&(((lbitset_elt *)(X))->words)))
124 #define LBITSET_CURRENT(X) LBITSET_CURRENT1((X)->b.cdata)
126 #define LBITSET_HEAD(X) ((X)->l.head)
127 #define LBITSET_TAIL(X) ((X)->l.tail)
129 /* Allocate a lbitset element. The bits are not cleared. */
130 static inline lbitset_elt
*
135 if (lbitset_free_list
!= 0)
137 elt
= lbitset_free_list
;
138 lbitset_free_list
= elt
->next
;
142 if (!lbitset_obstack_init
)
144 lbitset_obstack_init
= 1;
146 /* Let particular systems override the size of a chunk. */
148 #ifndef OBSTACK_CHUNK_SIZE
149 #define OBSTACK_CHUNK_SIZE 0
152 /* Let them override the alloc and free routines too. */
154 #ifndef OBSTACK_CHUNK_ALLOC
155 #define OBSTACK_CHUNK_ALLOC xmalloc
158 #ifndef OBSTACK_CHUNK_FREE
159 #define OBSTACK_CHUNK_FREE free
162 #if !defined(__GNUC__) || (__GNUC__ < 2)
163 #define __alignof__(type) 0
166 obstack_specify_allocation (&lbitset_obstack
, OBSTACK_CHUNK_SIZE
,
167 __alignof__ (lbitset_elt
),
168 (void *(*)PARAMS ((long)))
170 (void (*)PARAMS ((void *)))
174 /* Perhaps we should add a number of new elements to the free
176 elt
= (lbitset_elt
*) obstack_alloc (&lbitset_obstack
,
177 sizeof (lbitset_elt
));
184 /* Allocate a lbitset element. The bits are cleared. */
185 static inline lbitset_elt
*
186 lbitset_elt_calloc ()
190 elt
= lbitset_elt_alloc ();
191 memset (elt
->words
, 0, sizeof (elt
->words
));
197 lbitset_elt_free (elt
)
200 elt
->next
= lbitset_free_list
;
201 lbitset_free_list
= elt
;
205 /* Unlink element ELT from bitset BSET. */
207 lbitset_elt_unlink (bset
, elt
)
211 lbitset_elt
*next
= elt
->next
;
212 lbitset_elt
*prev
= elt
->prev
;
220 if (LBITSET_HEAD (bset
) == elt
)
221 LBITSET_HEAD (bset
) = next
;
222 if (LBITSET_TAIL (bset
) == elt
)
223 LBITSET_TAIL (bset
) = prev
;
225 /* Update cache pointer. Since the first thing we try is to insert
226 before current, make current the next entry in preference to the
228 if (LBITSET_CURRENT (bset
) == elt
)
232 bset
->b
.cdata
= next
->words
;
233 bset
->b
.cindex
= next
->index
;
237 bset
->b
.cdata
= prev
->words
;
238 bset
->b
.cindex
= prev
->index
;
247 lbitset_elt_free (elt
);
251 /* Cut the chain of bitset BSET before element ELT and free the
254 lbitset_prune (bset
, elt
)
265 LBITSET_TAIL (bset
) = elt
->prev
;
266 bset
->b
.cdata
= elt
->prev
->words
;
267 bset
->b
.cindex
= elt
->prev
->index
;
272 LBITSET_HEAD (bset
) = 0;
273 LBITSET_TAIL (bset
) = 0;
278 for (; elt
; elt
= next
)
281 lbitset_elt_free (elt
);
286 /* Return nonzero if all bits in an element are zero. */
288 lbitset_elt_zero_p (elt
)
293 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++)
301 /* Link the bitset element into the current bitset linked list. */
303 lbitset_elt_link (bset
, elt
)
307 bitset_windex windex
= elt
->index
;
309 lbitset_elt
*current
;
312 current
= LBITSET_CURRENT (bset
);
314 current
= LBITSET_HEAD (bset
);
316 /* If this is the first and only element, add it in. */
317 if (LBITSET_HEAD (bset
) == 0)
319 elt
->next
= elt
->prev
= 0;
320 LBITSET_HEAD (bset
) = elt
;
321 LBITSET_TAIL (bset
) = elt
;
324 /* If this index is less than that of the current element, it goes
325 somewhere before the current element. */
326 else if (windex
< bset
->b
.cindex
)
329 ptr
->prev
&& ptr
->prev
->index
> windex
; ptr
= ptr
->prev
)
333 ptr
->prev
->next
= elt
;
335 LBITSET_HEAD (bset
) = elt
;
337 elt
->prev
= ptr
->prev
;
342 /* Otherwise, it must go somewhere after the current element. */
346 ptr
->next
&& ptr
->next
->index
< windex
; ptr
= ptr
->next
)
350 ptr
->next
->prev
= elt
;
352 LBITSET_TAIL (bset
) = elt
;
354 elt
->next
= ptr
->next
;
359 /* Set up so this is the first element searched. */
360 bset
->b
.cindex
= windex
;
361 bset
->b
.csize
= LBITSET_ELT_WORDS
;
362 bset
->b
.cdata
= elt
->words
;
367 lbitset_elt_find (bset
, windex
, mode
)
369 bitset_windex windex
;
370 enum lbitset_find_mode mode
;
373 lbitset_elt
*current
;
377 current
= LBITSET_CURRENT (bset
);
378 /* Check if element is the cached element. */
379 if ((windex
- bset
->b
.cindex
) < bset
->b
.csize
)
384 current
= LBITSET_HEAD (bset
);
389 if (windex
< bset
->b
.cindex
)
392 elt
->prev
&& elt
->index
> windex
; elt
= elt
->prev
)
398 elt
->next
&& (elt
->index
+ LBITSET_ELT_WORDS
- 1) < windex
;
403 /* ELT is the nearest to the one we want. If it's not the one
404 we want, the one we want does not exist. */
405 if (elt
&& (windex
- elt
->index
) < LBITSET_ELT_WORDS
)
407 bset
->b
.cindex
= elt
->index
;
408 bset
->b
.csize
= LBITSET_ELT_WORDS
;
409 bset
->b
.cdata
= elt
->words
;
420 windex
-= windex
% LBITSET_ELT_WORDS
;
422 elt
= lbitset_elt_calloc ();
424 lbitset_elt_link (bset
, elt
);
428 return &lbitset_zero_elts
[0];
436 /* Weed out the zero elements from the list. */
444 for (elt
= LBITSET_HEAD (bset
); elt
; elt
= next
)
447 if (lbitset_elt_zero_p (elt
))
448 lbitset_elt_unlink (bset
, elt
);
453 /* Set all bits in the bitset to zero. */
460 head
= LBITSET_HEAD (bset
);
464 /* Clear a bitset by freeing the linked list at the head element. */
465 lbitset_prune (bset
, head
);
469 /* Return 1 if DST == SRC. */
471 lbitset_equal_p (dst
, src
)
484 for (selt
= LBITSET_HEAD (src
), delt
= LBITSET_HEAD (dst
);
485 selt
&& delt
; selt
= selt
->next
, delt
= delt
->next
)
487 if (selt
->index
!= delt
->index
)
490 for (j
= 0; j
< LBITSET_ELT_WORDS
; j
++)
491 if (delt
->words
[j
] != selt
->words
[j
])
494 return !selt
&& !delt
;
498 /* Copy bits from bitset SRC to bitset DST. */
500 lbitset_copy (dst
, src
)
514 head
= LBITSET_HEAD (src
);
519 for (elt
= head
; elt
; elt
= elt
->next
)
521 tmp
= lbitset_elt_alloc ();
522 tmp
->index
= elt
->index
;
528 LBITSET_HEAD (dst
) = tmp
;
531 memcpy (tmp
->words
, elt
->words
, sizeof (elt
->words
));
533 LBITSET_TAIL (dst
) = tmp
;
535 dst
->b
.csize
= LBITSET_ELT_WORDS
;
536 dst
->b
.cdata
= LBITSET_HEAD (dst
)->words
;
537 dst
->b
.cindex
= LBITSET_HEAD (dst
)->index
;
541 /* Copy bits from bitset SRC to bitset DST. Return non-zero if
542 bitsets different. */
544 lbitset_copy_cmp (dst
, src
)
551 if (!LBITSET_HEAD (dst
))
553 lbitset_copy (dst
, src
);
554 return LBITSET_HEAD (src
) != 0;
557 if (lbitset_equal_p (dst
, src
))
560 lbitset_copy (dst
, src
);
565 /* Return size in bits of bitset SRC. */
572 elt
= LBITSET_TAIL (src
);
576 /* Return current size of bitset in bits. */
577 return (elt
->index
+ LBITSET_ELT_WORDS
) * BITSET_WORD_BITS
;
581 /* Set bit BITNO in bitset DST. */
583 lbitset_set (dst
, bitno
)
587 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
589 lbitset_elt_find (dst
, windex
, LBITSET_CREATE
);
591 dst
->b
.cdata
[windex
- dst
->b
.cindex
] |=
592 (bitset_word
) 1 << (bitno
% BITSET_WORD_BITS
);
596 /* Reset bit BITNO in bitset DST. */
598 lbitset_reset (dst
, bitno
)
602 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
604 if (!lbitset_elt_find (dst
, windex
, LBITSET_FIND
))
607 dst
->b
.cdata
[windex
- dst
->b
.cindex
] &=
608 ~((bitset_word
) 1 << (bitno
% BITSET_WORD_BITS
));
610 /* If all the data is zero, perhaps we should unlink it now... */
614 /* Test bit BITNO in bitset SRC. */
616 lbitset_test (src
, bitno
)
620 bitset_windex windex
= bitno
/ BITSET_WORD_BITS
;
622 if (!lbitset_elt_find (src
, windex
, LBITSET_FIND
))
625 return (src
->b
.cdata
[windex
- src
->b
.cindex
]
626 >> (bitno
% BITSET_WORD_BITS
)) & 1;
638 /* Find list of up to NUM bits set in BSET starting from and including
639 *NEXT and store in array LIST. Return with actual number of bits
640 found and with *NEXT indicating where search stopped. */
642 lbitset_list_reverse (bset
, list
, num
, next
)
648 bitset_bindex rbitno
;
651 bitset_bindex boffset
;
652 bitset_windex windex
;
656 bitset_bindex n_bits
;
658 elt
= LBITSET_TAIL (bset
);
662 n_bits
= (elt
->index
+ LBITSET_ELT_WORDS
) * BITSET_WORD_BITS
;
665 if (rbitno
>= n_bits
)
668 bitno
= n_bits
- (rbitno
+ 1);
670 windex
= bitno
/ BITSET_WORD_BITS
;
672 /* Skip back to starting element. */
673 for (; elt
&& elt
->index
> windex
; elt
= elt
->prev
)
679 if (windex
>= elt
->index
+ LBITSET_ELT_WORDS
)
681 /* We are trying to start in no-mans land so start
682 at end of current elt. */
683 bcount
= BITSET_WORD_BITS
- 1;
684 windex
= elt
->index
+ LBITSET_ELT_WORDS
- 1;
688 bcount
= bitno
% BITSET_WORD_BITS
;
692 boffset
= windex
* BITSET_WORD_BITS
;
694 /* If num is 1, we could speed things up with a binary search
695 of the word of interest. */
699 bitset_word
*srcp
= elt
->words
;
701 for (; (windex
- elt
->index
) < LBITSET_ELT_WORDS
;
702 windex
--, boffset
-= BITSET_WORD_BITS
,
703 bcount
= BITSET_WORD_BITS
- 1)
706 srcp
[windex
- elt
->index
] << (BITSET_WORD_BITS
- 1 - bcount
);
708 for (; word
; bcount
--)
710 if (word
& BITSET_MSB
)
712 list
[count
++] = boffset
+ bcount
;
715 *next
= n_bits
- (boffset
+ bcount
);
726 windex
= elt
->index
+ LBITSET_ELT_WORDS
- 1;
727 boffset
= windex
* BITSET_WORD_BITS
;
731 *next
= n_bits
- (boffset
+ 1);
736 /* Find list of up to NUM bits set in BSET starting from and including
737 *NEXT and store in array LIST. Return with actual number of bits
738 found and with *NEXT indicating where search stopped. */
740 lbitset_list (bset
, list
, num
, next
)
747 bitset_windex windex
;
753 head
= LBITSET_HEAD (bset
);
762 /* This is the most common case. */
764 /* Start with the first element. */
767 bitno
= windex
* BITSET_WORD_BITS
;
771 windex
= bitno
/ BITSET_WORD_BITS
;
773 /* Skip to starting element. */
775 elt
&& (elt
->index
+ LBITSET_ELT_WORDS
- 1) < windex
;
782 if (windex
< elt
->index
)
785 bitno
= windex
* BITSET_WORD_BITS
;
789 bitset_word
*srcp
= elt
->words
;
791 /* We are starting within an element. */
793 for (; (windex
- elt
->index
) < LBITSET_ELT_WORDS
; windex
++)
795 word
= srcp
[windex
- elt
->index
] >> (bitno
% BITSET_WORD_BITS
);
797 for (; word
; bitno
++)
801 list
[count
++] = bitno
;
810 bitno
= (windex
+ 1) * BITSET_WORD_BITS
;
817 bitno
= windex
* BITSET_WORD_BITS
;
823 /* If num is 1, we could speed things up with a binary search
824 of the word of interest. */
829 bitset_word
*srcp
= elt
->words
;
831 if ((count
+ LBITSET_ELT_BITS
) < num
)
833 /* The coast is clear, plant boot! */
835 #if LBITSET_ELT_WORDS == 2
839 if (!(word
& 0xffff))
849 for (; word
; bitno
++)
852 list
[count
++] = bitno
;
857 bitno
= windex
* BITSET_WORD_BITS
;
862 if (!(word
& 0xffff))
867 for (; word
; bitno
++)
870 list
[count
++] = bitno
;
875 bitno
= windex
* BITSET_WORD_BITS
;
877 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++)
882 if (!(word
& 0xffff))
892 for (; word
; bitno
++)
895 list
[count
++] = bitno
;
900 bitno
= windex
* BITSET_WORD_BITS
;
906 /* Tread more carefully since we need to check
907 if array overflows. */
909 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++)
911 for (word
= srcp
[i
]; word
; bitno
++)
915 list
[count
++] = bitno
;
925 bitno
= windex
* BITSET_WORD_BITS
;
933 bitno
= windex
* BITSET_WORD_BITS
;
943 lbitset_empty_p (dst
)
947 if (LBITSET_HEAD (dst
))
958 bitset_windex windex
;
961 /* This is a decidedly unfriendly operation for a linked list
962 bitset! It makes a sparse bitset become dense. An alternative
963 is to have a flag that indicates that the bitset stores the
964 complement of what it indicates. */
965 elt
= LBITSET_TAIL (dst
);
966 /* Ignore empty set. */
971 for (i
= 0; i
< windex
; i
+= LBITSET_ELT_WORDS
)
973 /* Create new elements if they cannot be found. */
974 elt
= lbitset_elt_find (dst
, i
, LBITSET_CREATE
);
975 memset (elt
->words
, -1, sizeof (elt
->words
));
981 lbitset_not (dst
, src
)
990 bitset_windex windex
;
992 /* This is another unfriendly operation for a linked list
994 elt
= LBITSET_TAIL (dst
);
995 /* Ignore empty set. */
1000 for (i
= 0; i
< windex
; i
+= LBITSET_ELT_WORDS
)
1002 /* Create new elements for dst if they cannot be found
1003 or substitute zero elements if src elements not found. */
1004 selt
= lbitset_elt_find (src
, i
, LBITSET_SUBST
);
1005 delt
= lbitset_elt_find (dst
, i
, LBITSET_CREATE
);
1007 for (j
= 0; j
< LBITSET_ELT_WORDS
; j
++)
1008 delt
->words
[j
] = ~selt
->words
[j
];
1015 /* Return 1 if DST == DST | SRC. */
1017 lbitset_subset_p (dst
, src
)
1025 for (selt
= LBITSET_HEAD (src
), delt
= LBITSET_HEAD (dst
);
1026 selt
|| delt
; selt
= selt
->next
, delt
= delt
->next
)
1029 selt
= &lbitset_zero_elts
[0];
1031 delt
= &lbitset_zero_elts
[0];
1032 else if (selt
->index
!= delt
->index
)
1034 if (selt
->index
< delt
->index
)
1036 lbitset_zero_elts
[2].next
= delt
;
1037 delt
= &lbitset_zero_elts
[2];
1041 lbitset_zero_elts
[1].next
= selt
;
1042 selt
= &lbitset_zero_elts
[1];
1046 for (j
= 0; j
< LBITSET_ELT_WORDS
; j
++)
1047 if (delt
->words
[j
] != (selt
->words
[j
] | delt
->words
[j
]))
1054 /* Return 1 if DST & SRC == 0. */
1056 lbitset_disjoint_p (dst
, src
)
1064 for (selt
= LBITSET_HEAD (src
), delt
= LBITSET_HEAD (dst
);
1065 selt
&& delt
; selt
= selt
->next
, delt
= delt
->next
)
1067 if (selt
->index
!= delt
->index
)
1069 if (selt
->index
< delt
->index
)
1071 lbitset_zero_elts
[2].next
= delt
;
1072 delt
= &lbitset_zero_elts
[2];
1076 lbitset_zero_elts
[1].next
= selt
;
1077 selt
= &lbitset_zero_elts
[1];
1079 /* Since the elements are different, there is no
1080 intersection of these elements. */
1084 for (j
= 0; j
< LBITSET_ELT_WORDS
; j
++)
1085 if (selt
->words
[j
] & delt
->words
[j
])
1093 lbitset_op3_cmp (dst
, src1
, src2
, op
)
1099 lbitset_elt
*selt1
= LBITSET_HEAD (src1
);
1100 lbitset_elt
*selt2
= LBITSET_HEAD (src2
);
1101 lbitset_elt
*delt
= LBITSET_HEAD (dst
);
1102 bitset_windex windex1
;
1103 bitset_windex windex2
;
1104 bitset_windex windex
;
1114 LBITSET_HEAD (dst
) = 0;
1117 windex1
= (selt1
) ? selt1
->index
: BITSET_WINDEX_MAX
;
1118 windex2
= (selt2
) ? selt2
->index
: BITSET_WINDEX_MAX
;
1120 while (selt1
|| selt2
)
1122 /* Figure out whether we need to substitute zero elements for
1124 if (windex1
== windex2
)
1129 selt1
= selt1
->next
;
1130 windex1
= (selt1
) ? selt1
->index
: BITSET_WINDEX_MAX
;
1131 selt2
= selt2
->next
;
1132 windex2
= (selt2
) ? selt2
->index
: BITSET_WINDEX_MAX
;
1134 else if (windex1
< windex2
)
1138 stmp2
= &lbitset_zero_elts
[0];
1139 selt1
= selt1
->next
;
1140 windex1
= (selt1
) ? selt1
->index
: BITSET_WINDEX_MAX
;
1145 stmp1
= &lbitset_zero_elts
[0];
1147 selt2
= selt2
->next
;
1148 windex2
= (selt2
) ? selt2
->index
: BITSET_WINDEX_MAX
;
1151 /* Find the appropriate element from DST. Begin by discarding
1152 elements that we've skipped. */
1153 while (delt
&& delt
->index
< windex
)
1158 lbitset_elt_free (dtmp
);
1160 if (delt
&& delt
->index
== windex
)
1166 dtmp
= lbitset_elt_calloc ();
1168 /* Do the operation, and if any bits are set, link it into the
1170 srcp1
= stmp1
->words
;
1171 srcp2
= stmp2
->words
;
1176 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1178 bitset_word tmp
= *srcp1
++ | *srcp2
++;
1189 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1191 bitset_word tmp
= *srcp1
++ & *srcp2
++;
1202 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1204 bitset_word tmp
= *srcp1
++ ^ *srcp2
++;
1214 case BITSET_OP_ANDN
:
1215 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++, dstp
++)
1217 bitset_word tmp
= *srcp1
++ & ~(*srcp2
++);
1231 if (!lbitset_elt_zero_p (dtmp
))
1233 dtmp
->index
= windex
;
1234 /* Perhaps this could be optimised... */
1235 lbitset_elt_link (dst
, dtmp
);
1239 lbitset_elt_free (dtmp
);
1243 /* If we have elements of DST left over, free them all. */
1247 lbitset_prune (dst
, delt
);
1255 lbitset_and_cmp (dst
, src1
, src2
)
1260 lbitset_elt
*selt1
= LBITSET_HEAD (src1
);
1261 lbitset_elt
*selt2
= LBITSET_HEAD (src2
);
1267 changed
= !LBITSET_HEAD (dst
);
1274 changed
= !LBITSET_HEAD (dst
);
1278 return lbitset_op3_cmp (dst
, src1
, src2
, BITSET_OP_AND
);
1283 lbitset_andn_cmp (dst
, src1
, src2
)
1288 lbitset_elt
*selt1
= LBITSET_HEAD (src1
);
1289 lbitset_elt
*selt2
= LBITSET_HEAD (src2
);
1294 return lbitset_copy_cmp (dst
, src1
);
1299 changed
= !LBITSET_HEAD (dst
);
1303 return lbitset_op3_cmp (dst
, src1
, src2
, BITSET_OP_ANDN
);
1308 lbitset_or_cmp (dst
, src1
, src2
)
1313 lbitset_elt
*selt1
= LBITSET_HEAD (src1
);
1314 lbitset_elt
*selt2
= LBITSET_HEAD (src2
);
1318 return lbitset_copy_cmp (dst
, src1
);
1322 return lbitset_copy_cmp (dst
, src2
);
1324 return lbitset_op3_cmp (dst
, src1
, src2
, BITSET_OP_OR
);
1329 lbitset_xor_cmp (dst
, src1
, src2
)
1334 lbitset_elt
*selt1
= LBITSET_HEAD (src1
);
1335 lbitset_elt
*selt2
= LBITSET_HEAD (src2
);
1339 return lbitset_copy_cmp (dst
, src1
);
1343 return lbitset_copy_cmp (dst
, src2
);
1345 return lbitset_op3_cmp (dst
, src1
, src2
, BITSET_OP_XOR
);
1350 /* Vector of operations for linked-list bitsets. */
1351 struct bitset_vtable lbitset_vtable
= {
1366 (PFV
) lbitset_and_cmp
,
1368 (PFV
) lbitset_andn_cmp
,
1370 (PFV
) lbitset_or_cmp
,
1372 (PFV
) lbitset_xor_cmp
,
1374 (PFV
) bitset_and_or_cmp_
,
1376 (PFV
) bitset_andn_or_cmp_
,
1377 bitset_andn_or_cmp_
,
1378 (PFV
) bitset_or_and_cmp_
,
1381 lbitset_list_reverse
,
1387 /* Return size of initial structure. */
1389 lbitset_bytes (n_bits
)
1390 bitset_bindex n_bits ATTRIBUTE_UNUSED
;
1392 return sizeof (struct bitset_struct
);
1396 /* Initialize a bitset. */
1398 lbitset_init (bset
, n_bits
)
1400 bitset_bindex n_bits ATTRIBUTE_UNUSED
;
1402 bset
->b
.vtable
= &lbitset_vtable
;
1408 lbitset_release_memory ()
1410 lbitset_free_list
= 0;
1411 if (lbitset_obstack_init
)
1413 lbitset_obstack_init
= 0;
1414 obstack_free (&lbitset_obstack
, NULL
);
1419 /* Function to be called from debugger to debug lbitset. */
1421 debug_lbitset (bset
)
1430 for (elt
= LBITSET_HEAD (bset
); elt
; elt
= elt
->next
)
1432 fprintf (stderr
, "Elt %lu\n", (unsigned long) elt
->index
);
1433 for (i
= 0; i
< LBITSET_ELT_WORDS
; i
++)
1438 word
= elt
->words
[i
];
1440 fprintf (stderr
, " Word %u:", i
);
1441 for (j
= 0; j
< LBITSET_WORD_BITS
; j
++)
1442 if ((word
& (1 << j
)))
1443 fprintf (stderr
, " %u", j
);
1444 fprintf (stderr
, "\n");