private static double[] removeAndSlice(final double[] values,final int begin,final int length,final double removedValue){
  MathArrays.verifyValues(values,begin,length);
  final double[] temp;
  final BitSet bits=new BitSet(length);
  for (int i=begin; i < begin + length; i++) {
    if (Precision.equalsIncludingNaN(removedValue,values[i])) {
      bits.set(i - begin);
    }
  }
  if (bits.isEmpty()) {
    temp=copyOf(values,begin,length);
  }
 else   if (bits.cardinality() == length) {
    temp=new double[0];
  }
 else {
    temp=new double[length - bits.cardinality()];
    int start=begin;
    int dest=0;
    int nextOne=-1;
    int bitSetPtr=0;
    while ((nextOne=bits.nextSetBit(bitSetPtr)) != -1) {
      final int lengthToCopy=nextOne - bitSetPtr;
      System.arraycopy(values,start,temp,dest,lengthToCopy);
      dest+=lengthToCopy;
      start=begin + (bitSetPtr=bits.nextClearBit(nextOne));
    }
    if (start < begin + length) {
      System.arraycopy(values,start,temp,dest,begin + length - start);
    }
  }
  return temp;
}

private static double [ ] removeAndSlice ( final double [ ] values , final int begin , final int length , final double removedValue ) { MathArrays . verifyValues ( values , begin , length ) ; final double [ ] temp ; final BitSet bits = new BitSet ( length ) ; for ( int i = begin ; i < begin + length ; i ++ ) { if ( Precision . equalsIncludingNaN ( removedValue , values [ i ] ) ) { bits . set ( i - begin ) ; } } if ( bits . isEmpty ( ) ) { temp = copyOf ( values , begin , length ) ; } else if ( bits . cardinality ( ) == length ) { temp = new double [ 0 ] ; } else { temp = new double [ length - bits . cardinality ( ) ] ; int start = begin ; int dest = 0 ; int nextOne = - 1 ; int bitSetPtr = 0 ; while ( ( nextOne = bits . nextSetBit ( bitSetPtr ) ) != - 1 ) { final int lengthToCopy = nextOne - bitSetPtr ; System . arraycopy ( values , start , temp , dest , lengthToCopy ) ; dest += lengthToCopy ; start = begin + ( bitSetPtr = bits . nextClearBit ( nextOne ) ) ; } if ( start < begin + length ) { System . arraycopy ( values , start , temp , dest , begin + length - start ) ; } } return temp ; }
remove the occurrence of a given value in a copied slice of array defined by the array part from [ begin , begin + length ) .
