long (int id, long flags) { assert id >= 0 : id; if ((flags & ~mask) != 0) { throw new IllegalArgumentException("Flags must have <= " + bitsPerChunk + " bits set, but got: " + Long.toBinaryString(flags)); } int bitIndex = id / chunksPerWord * ConcurrentBitSetImpl.BITS_PER_WORD + (id % chunksPerWord) * bitsPerChunk; int oldFlags = bits.changeWord(bitIndex, word -> word & ~(mask << bitIndex) | ((int)flags << bitIndex)) >> bitIndex; return Integer.toUnsignedLong(oldFlags & mask); }