Logo Search packages:      
Sourcecode: lbt version File versions  Download package

unsigned BitVector::findNext ( unsigned  i  )  const [inline]

Find the next index at which there is a set bit

Parameters:
i the starting index (counting forward)
Returns:
0 if all following bits in the vector are clear; index of the next nonzero entry + 1 otherwise

Definition at line 155 of file BitVector.h.

References getNumWords(), m_bits, and m_size.

Referenced by nonzero(), printGates(), and translateFormula().

                                       {
    if (i >= m_size)
      return 0;

    register const word_t* w = &m_bits[i / (CHAR_BIT * sizeof (word_t))];
    register word_t bit = 1 << (i % (CHAR_BIT * sizeof (word_t)));

    if (*w >= bit) {
      // found in the same word
      do
      if (*w & bit)
        return i + 1;
      while (i++, bit <<= 1);
    }

    const word_t* const w_end = m_bits + getNumWords (m_size);

    // search in the remaining words
    while (++w < w_end) {
      if (!*w) continue;
      for (i = 1, bit = 1; !(*w & bit); bit <<= 1, i++);
      return i + (w - m_bits) * CHAR_BIT * sizeof (word_t);
    }

    return 0;
  }


Generated by  Doxygen 1.6.0   Back to index