(ebitset_set, ebitset_reset): Do not assume that bitset_word is the

same width as int.
(ebitset_op1): Use -1, not ~0, as memset arg (for portability to one's
complement hosts!).
This commit is contained in:
Paul Eggert
2002-08-12 14:20:35 +00:00
parent e601ff27f4
commit c837b82803

View File

@@ -578,7 +578,8 @@ ebitset_set (dst, bitno)
ebitset_elt_find (dst, windex, EBITSET_CREATE); ebitset_elt_find (dst, windex, EBITSET_CREATE);
dst->b.cdata[windex - dst->b.cindex] |= (1 << (bitno % BITSET_WORD_BITS)); dst->b.cdata[windex - dst->b.cindex] |=
(bitset_word) 1 << (bitno % BITSET_WORD_BITS);
} }
@@ -593,7 +594,8 @@ ebitset_reset (dst, bitno)
if (!ebitset_elt_find (dst, windex, EBITSET_FIND)) if (!ebitset_elt_find (dst, windex, EBITSET_FIND))
return; return;
dst->b.cdata[windex - dst->b.cindex] &= ~(1 << (bitno % BITSET_WORD_BITS)); dst->b.cdata[windex - dst->b.cindex] &=
~((bitset_word) 1 << (bitno % BITSET_WORD_BITS));
/* If all the data is zero, perhaps we should remove it now... /* If all the data is zero, perhaps we should remove it now...
However, there is a good chance that the element will be needed However, there is a good chance that the element will be needed
@@ -646,7 +648,6 @@ ebitset_reverse_list (bset, list, num, next)
bitset_windex woffset; bitset_windex woffset;
bitset_bindex count; bitset_bindex count;
bitset_windex size; bitset_windex size;
bitset_word word;
ebitset_elts *elts; ebitset_elts *elts;
if (EBITSET_OP_ZERO_P (bset)) if (EBITSET_OP_ZERO_P (bset))
@@ -674,21 +675,21 @@ ebitset_reverse_list (bset, list, num, next)
bcount = bitno % BITSET_WORD_BITS; bcount = bitno % BITSET_WORD_BITS;
boffset = windex * BITSET_WORD_BITS; boffset = windex * BITSET_WORD_BITS;
for (; eindex != ~0U; do
boffset = eindex * EBITSET_ELT_BITS - BITSET_WORD_BITS, eindex--)
{ {
ebitset_elt *elt; ebitset_elt *elt;
bitset_word *srcp;
elt = elts[eindex]; elt = elts[eindex];
if (!elt) if (elt)
continue; {
bitset_word *srcp;
srcp = EBITSET_WORDS (elt); srcp = EBITSET_WORDS (elt);
for (; woffset != ~0U; woffset--, boffset -= BITSET_WORD_BITS, do
bcount = BITSET_WORD_BITS - 1)
{ {
bitset_word word;
word = srcp[woffset] << (BITSET_WORD_BITS - 1 - bcount); word = srcp[woffset] << (BITSET_WORD_BITS - 1 - bcount);
for (; word; bcount--) for (; word; bcount--)
@@ -704,11 +705,19 @@ ebitset_reverse_list (bset, list, num, next)
} }
word <<= 1; word <<= 1;
} }
boffset -= BITSET_WORD_BITS;
bcount = BITSET_WORD_BITS - 1;
} }
while (woffset--);
woffset = EBITSET_ELT_WORDS; woffset = EBITSET_ELT_WORDS;
} }
boffset = eindex * EBITSET_ELT_BITS - BITSET_WORD_BITS;
}
while (eindex--);
*next = n_bits - (boffset + 1); *next = n_bits - (boffset + 1);
return count; return count;
} }
@@ -878,7 +887,7 @@ ebitset_op1 (dst, op)
we should just add pointers to a ones element. */ we should just add pointers to a ones element. */
elt = elt =
ebitset_elt_find (dst, j * EBITSET_ELT_WORDS, EBITSET_CREATE); ebitset_elt_find (dst, j * EBITSET_ELT_WORDS, EBITSET_CREATE);
memset (EBITSET_WORDS (elt), ~0, sizeof (EBITSET_WORDS (elt))); memset (EBITSET_WORDS (elt), -1, sizeof (EBITSET_WORDS (elt)));
} }
break; break;