/// <summary>Returns the index of the first set bit starting at the index specified. /// -1 is returned if there are no more set bits. /// </summary> public virtual long NextSetBit(long index) { int i = (int)(index >> 6); if (i >= wlen) { return(-1); } int subIndex = (int)index & 0x3f; // index within the word long word = (long)((ulong)bits[i] >> subIndex); // skip all the bits to the right of index if (word != 0) { return((((long)i) << 6) + (subIndex + BitUtil.Ntz(word))); } while (++i < wlen) { word = bits[i]; if (word != 0) { return((((long)i) << 6) + BitUtil.Ntz(word)); } } return(-1); }
/// <summary>Returns the index of the first set bit starting at the index specified. /// -1 is returned if there are no more set bits. /// </summary> public virtual int NextSetBit(int index) { int i = index >> 6; if (i >= wlen) { return(-1); } int subIndex = index & 0x3f; // index within the word long word = bits[i] >> subIndex; // skip all the bits to the right of index if (word != 0) { return((i << 6) + subIndex + BitUtil.Ntz(word)); } while (++i < wlen) { word = bits[i]; if (word != 0) { return((i << 6) + BitUtil.Ntz(word)); } } return(-1); }