private static void CopyBits(MyOpenBitSet compressedSet, int val, int offset, int length)
 {
     long[] bits = compressedSet.Bits;
     int index = (int)((uint)offset) >> 6;
     int skip = offset & 0x3f;
     val &= (int)(((uint)0xffffffff) >> (32 - length));
     bits[index] |= (((long)val) << skip);
     if (64 - skip < length)
     {
         bits[index + 1] |= (long)(((ulong)val) >> (64 - skip));
     }
 }
        ///<summary>Alternate implementation for compress
        ///   *  </summary>
        ///   * <param name="input"> </param>
        ///   * <returns> compressed bitset </returns>
        ///   * <exception cref="ArgumentException"> </exception>
        public virtual OpenBitSet Compress(int[] input)
        {
            if (_base == INVALID || _b == INVALID)
            {
                throw new ArgumentException(" Codec not initialized correctly ");
            }

            int BATCH_MAX = 1 << (_b - 1);
            // int validCount = (_batchSize - _exceptionCount)*_b +SIZE_MASK+BASE_MASK;

            // Compression mumbo jumbo
            // Set Size -b+base+compressedSet+exception*BASE_MASK
            MyOpenBitSet compressedSet = new MyOpenBitSet((_batchSize) * _b 
                + HEADER_MASK + _exceptionCount * (BASE_MASK));

            // System.out.println("Compressed Set Size : " + compressedSet.capacity());



            // Load the b
            CopyBits(compressedSet, _b, 0, BYTE_MASK);

            // copy the base value to BASE_MASK offset
            // copyBits(compressedSet, _base, BYTE_MASK, BASE_MASK);

            // Offset is the offset of the next location to place the value
            int offset = HEADER_MASK;
            int exceptionOffset = _exceptionOffset;
            int exceptionIndex = 0;

            // 1. Walk the list
            // TODO : Optimize this process.
            for (int i = 0; i < _batchSize; i++)
            {
                // else copy in the end
                if (input[i] < BATCH_MAX)
                {
                    CopyBits(compressedSet, input[i] << 1, offset, _b);
                }
                else
                {
                    // Copy the value to the exception location
                    // Add a bit marker to place
                    CopyBits(compressedSet, ((exceptionIndex << 1) | 0x1), offset, _b);
                    // System.out.println("Adding Exception
                    // Marker:"+(BATCH_MAX|(exceptionIndex-1)) + " at offset:"+offset);

                    // Copy the patch value to patch offset location
                    CopyBits(compressedSet, input[i], exceptionOffset, BASE_MASK);

                    // reset exceptionDelta
                    exceptionOffset += BASE_MASK;
                    exceptionIndex++;
                }

                offset += _b;
            }

            return compressedSet;
        }