Exemple #1
0
  /** Searches the vector for the first true value, starting at the \p last_bit_offset 'th bit
      \param[in] last_bit_offset the bit before the first to consider
	    \return the bit offset of the first true bit after \p last_bit_offset, or -1 if there is none
  */
  int OBBitVec::NextBit(int last_bit_offset) const
  {
    unsigned s;
    int bit;
    unsigned wrdcnt;
    ++ last_bit_offset;

    wrdcnt = (unsigned)last_bit_offset >> WORDROLL;

    if (wrdcnt >= GetSize())
      return(-1);

    if (_set[wrdcnt] != 0)
      {
        s = _set[wrdcnt] & bitsoff[last_bit_offset & WORDMASK];
        if (s)
          {
            LowBit(s,bit);
            if (bit != -1)
              return(bit + (wrdcnt << WORDROLL));
          }
      }
    ++ wrdcnt;

    while(wrdcnt < GetSize())
      {
        if (_set[wrdcnt] != 0)
          {
            s = _set[wrdcnt];
            LowBit(s, bit);

            if (bit != -1)
              return(bit + (wrdcnt << WORDROLL));
          }
        ++ wrdcnt;
      }

    return(-1);
  }
Exemple #2
0
 inline int Cal(int u) {int ret = 0; for (int i = u; i >= 1; i -= LowBit(i)) ret += a[i]; return ret;}
Exemple #3
0
 inline void Insert(int t, int u) {for (int i = t; i <= n; i += LowBit(i)) a[i] += u;}