Exemple #1
0
/* Copy bits from bitset SRC to bitset DST.  */
static inline void
tbitset_copy_ (bitset dst, bitset src)
{
  if (src == dst)
    return;

  tbitset_zero (dst);

  if (BITSET_NBITS_ (dst) != BITSET_NBITS_ (src))
    tbitset_resize (dst, BITSET_NBITS_ (src));

  tbitset_elts *selts = EBITSET_ELTS (src);
  tbitset_elts *delts = EBITSET_ELTS (dst);
  for (bitset_windex j = 0; j < EBITSET_SIZE (src); j++)
    {
      tbitset_elt *selt = selts[j];
      if (selt)
        {
          tbitset_elt *tmp = tbitset_elt_alloc ();
          delts[j] = tmp;
          memcpy (EBITSET_WORDS (tmp), EBITSET_WORDS (selt),
                  sizeof (EBITSET_WORDS (selt)));
        }
    }
  EBITSET_NONZERO_SET (dst);
}
Exemple #2
0
static bitset_bindex
vbitset_resize (bitset src, bitset_bindex n_bits)
{
  bitset_windex oldsize;
  bitset_windex newsize;

  if (n_bits == BITSET_NBITS_ (src))
    return n_bits;

  oldsize = VBITSET_SIZE (src);
  newsize = VBITSET_N_WORDS (n_bits);

  if (oldsize < newsize)
    {
      bitset_windex size;

      /* The bitset needs to grow.  If we already have enough memory
	 allocated, then just zero what we need.  */
      if (newsize > VBITSET_ASIZE (src))
	{
	  /* We need to allocate more memory.  When oldsize is
	     non-zero this means that we are changing the size, so
	     grow the bitset 25% larger than requested to reduce
	     number of reallocations.  */

	  if (oldsize == 0)
	    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,
	      (newsize - oldsize) * sizeof (bitset_word));
      VBITSET_SIZE (src) = newsize;
    }
  else
    {
      /* The bitset needs to shrink.  There's no point deallocating
	 the memory unless it is shrinking by a reasonable amount.  */
      if ((oldsize - newsize) >= oldsize / 2)
	{
	  VBITSET_WORDS (src)
	    = realloc (VBITSET_WORDS (src), newsize * sizeof (bitset_word));
	  VBITSET_ASIZE (src) = newsize;
	}

      /* Need to prune any excess bits.  FIXME.  */

      VBITSET_SIZE (src) = newsize;
    }

  BITSET_NBITS_ (src) = n_bits;
  return n_bits;
}
Exemple #3
0
static bitset_bindex
lbitset_resize (bitset src, bitset_bindex size)
{
    BITSET_NBITS_ (src) = size;

    /* Need to prune any excess bits.  FIXME.  */
    return size;
}