14 |
|
|
15 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
16 |
along with this program; if not, write to the Free Software |
along with this program; if not, write to the Free Software |
17 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
|
*/ |
19 |
|
|
20 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
21 |
#include "config.h" |
#include "config.h" |
22 |
#endif |
#endif |
23 |
|
|
24 |
#include "bbitset.h" |
#include "ebitset.h" |
25 |
#include "obstack.h" |
#include "obstack.h" |
26 |
#include <stdlib.h> |
#include <stdlib.h> |
27 |
|
|
312 |
|
|
313 |
|
|
314 |
static ebitset_elt * |
static ebitset_elt * |
315 |
ebitset_elt_find (bset, index, mode) |
ebitset_elt_find (bset, windex, mode) |
316 |
bitset bset; |
bitset bset; |
317 |
bitset_windex index; |
bitset_windex windex; |
318 |
enum ebitset_find_mode mode; |
enum ebitset_find_mode mode; |
319 |
{ |
{ |
320 |
ebitset_elt *elt; |
ebitset_elt *elt; |
322 |
unsigned int eindex; |
unsigned int eindex; |
323 |
ebitset_elts *elts; |
ebitset_elts *elts; |
324 |
|
|
325 |
eindex = index / EBITSET_ELT_WORDS; |
eindex = windex / EBITSET_ELT_WORDS; |
326 |
|
|
327 |
elts = EBITSET_ELTS (bset); |
elts = EBITSET_ELTS (bset); |
328 |
size = EBITSET_SIZE (bset); |
size = EBITSET_SIZE (bset); |
329 |
|
|
330 |
if (eindex < size) |
if (eindex < size) |
331 |
{ |
{ |
|
ebitset_elt *elt; |
|
|
|
|
332 |
if ((elt = elts[eindex])) |
if ((elt = elts[eindex])) |
333 |
{ |
{ |
334 |
if (EBITSET_WORDS (elt) == bset->b.cdata) |
if (EBITSET_WORDS (elt) == bset->b.cdata) |
580 |
bitset dst; |
bitset dst; |
581 |
bitset_bindex bitno; |
bitset_bindex bitno; |
582 |
{ |
{ |
583 |
bitset_windex index = bitno / BITSET_WORD_BITS; |
bitset_windex windex = bitno / BITSET_WORD_BITS; |
584 |
|
|
585 |
ebitset_elt_find (dst, index, EBITSET_CREATE); |
ebitset_elt_find (dst, windex, EBITSET_CREATE); |
586 |
|
|
587 |
dst->b.cdata[index - dst->b.cindex] |= (1 << (bitno % BITSET_WORD_BITS)); |
dst->b.cdata[windex - dst->b.cindex] |= (1 << (bitno % BITSET_WORD_BITS)); |
588 |
} |
} |
589 |
|
|
590 |
|
|
594 |
bitset dst; |
bitset dst; |
595 |
bitset_bindex bitno; |
bitset_bindex bitno; |
596 |
{ |
{ |
597 |
bitset_windex index = bitno / BITSET_WORD_BITS; |
bitset_windex windex = bitno / BITSET_WORD_BITS; |
598 |
|
|
599 |
if (!ebitset_elt_find (dst, index, EBITSET_FIND)) |
if (!ebitset_elt_find (dst, windex, EBITSET_FIND)) |
600 |
return; |
return; |
601 |
|
|
602 |
dst->b.cdata[index - dst->b.cindex] &= ~(1 << (bitno % BITSET_WORD_BITS)); |
dst->b.cdata[windex - dst->b.cindex] &= ~(1 << (bitno % BITSET_WORD_BITS)); |
603 |
|
|
604 |
/* If all the data is zero, perhaps we should remove it now... |
/* If all the data is zero, perhaps we should remove it now... |
605 |
However, there could be a good chance that the element will be needed |
However, there is a good chance that the element will be needed |
606 |
again soon. */ |
again soon. */ |
607 |
} |
} |
608 |
|
|
613 |
bitset src; |
bitset src; |
614 |
bitset_bindex bitno; |
bitset_bindex bitno; |
615 |
{ |
{ |
616 |
bitset_windex index = bitno / BITSET_WORD_BITS; |
bitset_windex windex = bitno / BITSET_WORD_BITS; |
617 |
|
|
618 |
if (!ebitset_elt_find (src, index, EBITSET_FIND)) |
if (!ebitset_elt_find (src, windex, EBITSET_FIND)) |
619 |
return 0; |
return 0; |
620 |
|
|
621 |
return (src->b. |
return (src->b. |
622 |
cdata[index - src->b.cindex] >> (bitno % BITSET_WORD_BITS)) & 1; |
cdata[windex - src->b.cindex] >> (bitno % BITSET_WORD_BITS)) & 1; |
623 |
} |
} |
624 |
|
|
625 |
|
|
645 |
bitset_bindex n_bits; |
bitset_bindex n_bits; |
646 |
bitset_bindex bitno; |
bitset_bindex bitno; |
647 |
bitset_bindex rbitno; |
bitset_bindex rbitno; |
648 |
unsigned int bitcnt; |
unsigned int bcount; |
649 |
bitset_bindex bitoff; |
bitset_bindex boffset; |
|
bitset_windex index; |
|
|
unsigned int eindex; |
|
650 |
bitset_windex windex; |
bitset_windex windex; |
651 |
|
unsigned int eindex; |
652 |
|
bitset_windex woffset; |
653 |
bitset_bindex count; |
bitset_bindex count; |
654 |
bitset_windex size; |
bitset_windex size; |
655 |
bitset_word word; |
bitset_word word; |
669 |
|
|
670 |
bitno = n_bits - (rbitno + 1); |
bitno = n_bits - (rbitno + 1); |
671 |
|
|
672 |
index = bitno / BITSET_WORD_BITS; |
windex = bitno / BITSET_WORD_BITS; |
673 |
eindex = bitno / EBITSET_ELT_BITS; |
eindex = bitno / EBITSET_ELT_BITS; |
674 |
windex = index - eindex * EBITSET_ELT_WORDS; |
woffset = windex - eindex * EBITSET_ELT_WORDS; |
675 |
|
|
676 |
/* If num is 1, we could speed things up with a binary search |
/* If num is 1, we could speed things up with a binary search |
677 |
of the word of interest. */ |
of the word of interest. */ |
678 |
|
|
679 |
count = 0; |
count = 0; |
680 |
bitcnt = bitno % BITSET_WORD_BITS; |
bcount = bitno % BITSET_WORD_BITS; |
681 |
bitoff = index * BITSET_WORD_BITS; |
boffset = windex * BITSET_WORD_BITS; |
682 |
|
|
683 |
for (; eindex != ~0U; eindex--) |
for (; eindex != ~0U; |
684 |
|
boffset = eindex * EBITSET_ELT_BITS - BITSET_WORD_BITS, eindex--) |
685 |
{ |
{ |
686 |
ebitset_elt *elt; |
ebitset_elt *elt; |
687 |
bitset_word *srcp; |
bitset_word *srcp; |
692 |
|
|
693 |
srcp = EBITSET_WORDS (elt); |
srcp = EBITSET_WORDS (elt); |
694 |
|
|
695 |
for (; windex != ~0U; windex--, bitoff -= BITSET_WORD_BITS, |
for (; woffset != ~0U; woffset--, boffset -= BITSET_WORD_BITS, |
696 |
bitcnt = BITSET_WORD_BITS - 1) |
bcount = BITSET_WORD_BITS - 1) |
697 |
{ |
{ |
698 |
word = srcp[windex] << (BITSET_WORD_BITS - 1 - bitcnt); |
word = srcp[woffset] << (BITSET_WORD_BITS - 1 - bcount); |
699 |
|
|
700 |
for (; word; bitcnt--) |
for (; word; bcount--) |
701 |
{ |
{ |
702 |
if (word & BITSET_MSB) |
if (word & BITSET_MSB) |
703 |
{ |
{ |
704 |
list[count++] = bitoff + bitcnt; |
list[count++] = boffset + bcount; |
705 |
if (count >= num) |
if (count >= num) |
706 |
{ |
{ |
707 |
*next = n_bits - (bitoff + bitcnt); |
*next = n_bits - (boffset + bcount); |
708 |
return count; |
return count; |
709 |
} |
} |
710 |
} |
} |
712 |
} |
} |
713 |
} |
} |
714 |
|
|
715 |
windex = EBITSET_ELT_WORDS; |
woffset = EBITSET_ELT_WORDS; |
716 |
} |
} |
717 |
|
|
718 |
*next = n_bits - (bitoff + 1); |
*next = n_bits - (boffset + 1); |
719 |
return count; |
return count; |
720 |
} |
} |
721 |
|
|
731 |
bitset_bindex *next; |
bitset_bindex *next; |
732 |
{ |
{ |
733 |
bitset_bindex bitno; |
bitset_bindex bitno; |
734 |
bitset_windex index; |
bitset_windex windex; |
735 |
unsigned int eindex; |
unsigned int eindex; |
736 |
bitset_bindex count; |
bitset_bindex count; |
737 |
bitset_windex size; |
bitset_windex size; |
756 |
elt = elts[eindex]; |
elt = elts[eindex]; |
757 |
if (elt) |
if (elt) |
758 |
{ |
{ |
759 |
bitset_windex windex; |
bitset_windex woffset; |
760 |
bitset_word *srcp = EBITSET_WORDS (elt); |
bitset_word *srcp = EBITSET_WORDS (elt); |
761 |
|
|
762 |
index = bitno / BITSET_WORD_BITS; |
windex = bitno / BITSET_WORD_BITS; |
763 |
windex = eindex / EBITSET_ELT_WORDS; |
woffset = eindex / EBITSET_ELT_WORDS; |
764 |
|
|
765 |
for (; (index - windex) < EBITSET_ELT_WORDS; index++) |
for (; (windex - woffset) < EBITSET_ELT_WORDS; windex++) |
766 |
{ |
{ |
767 |
word = srcp[index - windex] >> (bitno % BITSET_WORD_BITS); |
word = srcp[windex - woffset] >> (bitno % BITSET_WORD_BITS); |
768 |
|
|
769 |
for (; word; bitno++) |
for (; word; bitno++) |
770 |
{ |
{ |
779 |
} |
} |
780 |
word >>= 1; |
word >>= 1; |
781 |
} |
} |
782 |
bitno = (index + 1) * BITSET_WORD_BITS; |
bitno = (windex + 1) * BITSET_WORD_BITS; |
783 |
} |
} |
784 |
} |
} |
785 |
|
|
793 |
for (; eindex < size; eindex++) |
for (; eindex < size; eindex++) |
794 |
{ |
{ |
795 |
int i; |
int i; |
|
ebitset_elt *elt; |
|
796 |
bitset_word *srcp; |
bitset_word *srcp; |
797 |
|
|
798 |
elt = elts[eindex]; |
elt = elts[eindex]; |
800 |
continue; |
continue; |
801 |
|
|
802 |
srcp = EBITSET_WORDS (elt); |
srcp = EBITSET_WORDS (elt); |
803 |
index = eindex * EBITSET_ELT_WORDS; |
windex = eindex * EBITSET_ELT_WORDS; |
804 |
|
|
805 |
if ((count + EBITSET_ELT_BITS) < num) |
if ((count + EBITSET_ELT_BITS) < num) |
806 |
{ |
{ |
807 |
/* The coast is clear, plant boot! */ |
/* The coast is clear, plant boot! */ |
808 |
|
|
809 |
for (i = 0; i < EBITSET_ELT_WORDS; i++, index++) |
for (i = 0; i < EBITSET_ELT_WORDS; i++, windex++) |
810 |
{ |
{ |
811 |
bitno = index * BITSET_WORD_BITS; |
bitno = windex * BITSET_WORD_BITS; |
812 |
|
|
813 |
word = srcp[i]; |
word = srcp[i]; |
814 |
if (word) |
if (word) |
837 |
/* Tread more carefully since we need to check |
/* Tread more carefully since we need to check |
838 |
if array overflows. */ |
if array overflows. */ |
839 |
|
|
840 |
for (i = 0; i < EBITSET_ELT_WORDS; i++, index++) |
for (i = 0; i < EBITSET_ELT_WORDS; i++, windex++) |
841 |
{ |
{ |
842 |
bitno = index * BITSET_WORD_BITS; |
bitno = windex * BITSET_WORD_BITS; |
843 |
|
|
844 |
for (word = srcp[i]; word; bitno++) |
for (word = srcp[i]; word; bitno++) |
845 |
{ |
{ |
952 |
|
|
953 |
for (j = 0; j < ssize; j++) |
for (j = 0; j < ssize; j++) |
954 |
{ |
{ |
|
ebitset_elt *selt; |
|
|
ebitset_elt *delt; |
|
|
|
|
955 |
selt = j < ssize ? selts[j] : 0; |
selt = j < ssize ? selts[j] : 0; |
956 |
delt = j < dsize ? delts[j] : 0; |
delt = j < dsize ? delts[j] : 0; |
957 |
|
|
988 |
|
|
989 |
for (j = 0; j < ssize; j++) |
for (j = 0; j < ssize; j++) |
990 |
{ |
{ |
|
ebitset_elt *selt; |
|
|
ebitset_elt *delt; |
|
|
|
|
991 |
selt = j < ssize ? selts[j] : 0; |
selt = j < ssize ? selts[j] : 0; |
992 |
delt = j < dsize ? delts[j] : 0; |
delt = j < dsize ? delts[j] : 0; |
993 |
|
|
994 |
if (!selt && !delt) |
if (!selt || !delt) |
995 |
continue; |
continue; |
996 |
|
|
|
if (!selt) |
|
|
selt = &ebitset_zero_elts[0]; |
|
|
if (!delt) |
|
|
delt = &ebitset_zero_elts[0]; |
|
|
|
|
997 |
for (i = 0; i < EBITSET_ELT_WORDS; i++) |
for (i = 0; i < EBITSET_ELT_WORDS; i++) |
998 |
if ((EBITSET_WORDS (selt)[i] & EBITSET_WORDS (delt)[i])) |
if ((EBITSET_WORDS (selt)[i] & EBITSET_WORDS (delt)[i])) |
999 |
return 0; |
return 0; |
1157 |
|
|
1158 |
if (*dstp != tmp) |
if (*dstp != tmp) |
1159 |
{ |
{ |
|
changed = 1; |
|
|
*dstp = tmp; |
|
|
} |
|
|
} |
|
|
break; |
|
|
|
|
|
case BITSET_OP_ORN: |
|
|
for (i = 0; i < EBITSET_ELT_WORDS; i++, dstp++) |
|
|
{ |
|
|
bitset_word tmp = *srcp1++ | ~(*srcp2++); |
|
|
|
|
|
if (*dstp != tmp) |
|
|
{ |
|
1160 |
changed = 1; |
changed = 1; |
1161 |
*dstp = tmp; |
*dstp = tmp; |
1162 |
} |
} |