public int nextBit(int x) {
        int windex = x >>> wordshift;
        if (windex >= bits.length) return -1;
        int word = bits[windex] & ~((1 << (x & wordmask))-1);
        while (true) {
            if (word != 0)
                return (windex << wordshift) + trailingZeroBits(word);
            windex++;
            if (windex >= bits.length) return -1;
            word = bits[windex];
        }
    }