/* Variable array bitsets.
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004, 2005, 2006, 2009 Free Software
+ Foundation, Inc.
Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz).
- This program is free software; you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
+#include <config.h>
#include "vbitset.h"
+
#include <stdlib.h>
#include <string.h>
/* This file implements variable size bitsets stored as a variable
length array of words. Any unused bits in the last word must be
- zero.
+ zero.
Note that binary or ternary operations assume that each bitset operand
has the same size.
*/
-static void vbitset_unused_clear PARAMS ((bitset));
+static void vbitset_unused_clear (bitset);
-static void vbitset_set PARAMS ((bitset, bitset_bindex));
-static void vbitset_reset PARAMS ((bitset, bitset_bindex));
-static bool vbitset_test PARAMS ((bitset, bitset_bindex));
-static bitset_bindex vbitset_list PARAMS ((bitset, bitset_bindex *,
- bitset_bindex,
- bitset_bindex *));
-static bitset_bindex vbitset_list_reverse PARAMS ((bitset, bitset_bindex *,
- bitset_bindex,
- bitset_bindex *));
+static void vbitset_set (bitset, bitset_bindex);
+static void vbitset_reset (bitset, bitset_bindex);
+static bool vbitset_test (bitset, bitset_bindex);
+static bitset_bindex vbitset_list (bitset, bitset_bindex *,
+ bitset_bindex, bitset_bindex *);
+static bitset_bindex vbitset_list_reverse (bitset, bitset_bindex *,
+ bitset_bindex, bitset_bindex *);
#define VBITSET_N_WORDS(N) (((N) + BITSET_WORD_BITS - 1) / BITSET_WORD_BITS)
#define VBITSET_WORDS(X) ((X)->b.cdata)
#define VBITSET_SIZE(X) ((X)->b.csize)
#define VBITSET_ASIZE(X) ((X)->v.size)
-
+#undef min
+#undef max
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
{
bitset_windex size;
- /* The bitset needs to grow. If we already have enough memory
+ /* The bitset needs to grow. If we already have enough memory
allocated, then just zero what we need. */
if (newsize > VBITSET_ASIZE (src))
{
size = newsize;
else
size = newsize + newsize / 4;
-
+
VBITSET_WORDS (src)
= realloc (VBITSET_WORDS (src), size * sizeof (bitset_word));
VBITSET_ASIZE (src) = size;
}
- memset (VBITSET_WORDS (src) + oldsize, 0,
+ memset (VBITSET_WORDS (src) + oldsize, 0,
(newsize - oldsize) * sizeof (bitset_word));
VBITSET_SIZE (src) = newsize;
}
sizeof (bitset_word) * (dsize - ssize));
}
-
+
static bool
vbitset_equal_p (bitset dst, bitset src)
{
bitset_word *dstp = VBITSET_WORDS (dst);
bitset_windex ssize = VBITSET_SIZE (src);
bitset_windex dsize = VBITSET_SIZE (dst);
-
+
for (i = 0; i < min (ssize, dsize); i++, dstp++, srcp++)
if (*dstp != (*srcp | *dstp))
return 0;
for (i = 0; i < min (ssize1, ssize2); i++)
*dstp++ = *src1p++ & *src2p++;
-
+
memset (dstp, 0, sizeof (bitset_word) * (dsize - min (ssize1, ssize2)));
}
for (i = 0; i < min (ssize1, ssize2); i++, dstp++)
{
bitset_word tmp = *src1p++ & *src2p++;
-
+
if (*dstp != tmp)
{
changed = 1;
*dstp = tmp;
}
}
-
+
if (ssize2 > ssize1)
{
src1p = src2p;
for (i = 0; i < min (ssize1, ssize2); i++)
*dstp++ = *src1p++ & ~(*src2p++);
-
+
if (ssize2 > ssize1)
{
for (; i < ssize2; i++)
for (i = 0; i < min (ssize1, ssize2); i++, dstp++)
{
bitset_word tmp = *src1p++ & ~(*src2p++);
-
+
if (*dstp != tmp)
{
changed = 1;
*dstp = tmp;
}
}
-
+
if (ssize2 > ssize1)
{
for (; i < ssize2; i++, dstp++)
for (; i < ssize1; i++, dstp++)
{
bitset_word tmp = *src1p++;
-
+
if (*dstp != tmp)
{
changed = 1;
for (i = 0; i < min (ssize1, ssize2); i++)
*dstp++ = *src1p++ | *src2p++;
-
+
if (ssize2 > ssize1)
{
src1p = src2p;
for (i = 0; i < min (ssize1, ssize2); i++, dstp++)
{
bitset_word tmp = *src1p++ | *src2p++;
-
+
if (*dstp != tmp)
{
changed = 1;
*dstp = tmp;
}
}
-
+
if (ssize2 > ssize1)
{
src1p = src2p;
for (; i < ssize1; i++, dstp++)
{
bitset_word tmp = *src1p++;
-
+
if (*dstp != tmp)
{
changed = 1;
for (i = 0; i < min (ssize1, ssize2); i++)
*dstp++ = *src1p++ ^ *src2p++;
-
+
if (ssize2 > ssize1)
{
src1p = src2p;
for (i = 0; i < min (ssize1, ssize2); i++, dstp++)
{
bitset_word tmp = *src1p++ ^ *src2p++;
-
+
if (*dstp != tmp)
{
changed = 1;
*dstp = tmp;
}
}
-
+
if (ssize2 > ssize1)
{
src1p = src2p;
for (; i < ssize1; i++, dstp++)
{
bitset_word tmp = *src1p++;
-
+
if (*dstp != tmp)
{
changed = 1;
bitset_word *src3p;
bitset_word *dstp;
bitset_windex size;
-
+
if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
|| BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
{
bitset_word *src3p;
bitset_word *dstp;
bitset_windex size;
-
+
if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
|| BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
return bitset_and_or_cmp_ (dst, src1, src2, src3);
src3p = VBITSET_WORDS (src3);
dstp = VBITSET_WORDS (dst);
size = VBITSET_SIZE (dst);
-
+
for (i = 0; i < size; i++, dstp++)
{
bitset_word tmp = (*src1p++ & *src2p++) | *src3p++;
-
+
if (*dstp != tmp)
{
changed = 1;
bitset_word *src3p;
bitset_word *dstp;
bitset_windex size;
-
+
if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
|| BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
{
bitset_word *src3p;
bitset_word *dstp;
bitset_windex size;
-
+
if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
|| BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
return bitset_andn_or_cmp_ (dst, src1, src2, src3);
src3p = VBITSET_WORDS (src3);
dstp = VBITSET_WORDS (dst);
size = VBITSET_SIZE (dst);
-
+
for (i = 0; i < size; i++, dstp++)
{
bitset_word tmp = (*src1p++ & ~(*src2p++)) | *src3p++;
-
+
if (*dstp != tmp)
{
changed = 1;
bitset_word *src3p;
bitset_word *dstp;
bitset_windex size;
-
+
if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
|| BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
{
src3p = VBITSET_WORDS (src3);
dstp = VBITSET_WORDS (dst);
size = VBITSET_SIZE (dst);
-
+
for (i = 0; i < size; i++)
*dstp++ = (*src1p++ | *src2p++) & *src3p++;
}
bitset_word *src3p;
bitset_word *dstp;
bitset_windex size;
-
+
if (BITSET_NBITS_ (src1) != BITSET_NBITS_ (src2)
|| BITSET_NBITS_ (src1) != BITSET_NBITS_ (src3))
return bitset_or_and_cmp_ (dst, src1, src2, src3);
src3p = VBITSET_WORDS (src3);
dstp = VBITSET_WORDS (dst);
size = VBITSET_SIZE (dst);
-
+
for (i = 0; i < size; i++, dstp++)
{
bitset_word tmp = (*src1p++ | *src2p++) & *src3p++;
-
+
if (*dstp != tmp)
{
changed = 1;
}
-void
+static void
vbitset_copy (bitset dst, bitset src)
{
if (BITSET_COMPATIBLE_ (dst, src))