private NBSI help_copy_impl( int i ) {
      // Handle every 64th bit via using a nested array
      NBSI old = this;          // The bit array being copied from
      NBSI nnn = _new;          // The bit array being copied to
      if( nnn == null ) return this; // Promoted already
      int j = i;                // The bit index being added
      while( (j&63) == 63 ) {   // Bit 64? (low 6 bits are all set)
        old = old._nbsi64;      // Recurse
        nnn = nnn._nbsi64;      // Recurse
        j = j>>6;               // Strip off low 6 bits (all set)
      }

      // Transit from state 1: word is not immutable yet
      // Immutable is in bit 63, the sign bit.
      long bits = old._bits[j>>6];
      while( bits >= 0 ) {      // Still in state (1)?
        long oldbits = bits;
        bits |= mask(63);       // Target state of bits: sign-bit means immutable
        if( old.CAS( j>>6, oldbits, bits ) ) {
          if( oldbits == 0 ) _copyDone.addAndGet(1);
          break;                // Success - old array word is now immutable
        }
        bits = old._bits[j>>6]; // Retry if CAS failed
      }

      // Transit from state 2: non-zero in old and zero in new
      if( bits != mask(63) ) {  // Non-zero in old?
        long new_bits = nnn._bits[j>>6];
        if( new_bits == 0 ) {   // New array is still zero
          new_bits = bits & ~mask(63); // Desired new value: a mutable copy of bits
          // One-shot CAS attempt, no loop, from 0 to non-zero.
          // If it fails, somebody else did the copy for us
          if( !nnn.CAS( j>>6, 0, new_bits ) )
            new_bits = nnn._bits[j>>6]; // Since it failed, get the new value
          assert new_bits != 0;
        }

        // Transit from state 3: non-zero in old and non-zero in new
        // One-shot CAS attempt, no loop, from non-zero to 0 (but immutable)
        if( old.CAS( j>>6, bits, mask(63) ) )
          _copyDone.addAndGet(1); // One more word finished copying
      }

      // Now in state 4: zero (and immutable) in old

      // Return the self bitvector for 'fluid' programming style
      return this;
    }
Standard Java {@link Iterator}.  Not very efficient because it
auto-boxes the returned values.
jctools-core/src/main/java/org/jctools/maps/NonBlockingSetInt.java