package water.fvec;

import water.*;

/**
 * The empty-compression function, where data is in 'int's.
 */
public class C4Chunk extends Chunk {
  static protected final long _NA = Integer.MIN_VALUE;
  C4Chunk( byte[] bs ) { _mem=bs; _start = -1; _len = _mem.length>>2; }
  @Override protected final long at8_impl( int i ) {
    long res = UDP.get4(_mem,i<<2);
    if( res == _NA ) throw new IllegalArgumentException("at8 but value is missing");
    return res;
  }
  @Override protected final double atd_impl( int i ) {
    long res = UDP.get4(_mem,i<<2);
    return res == _NA?Double.NaN:res;
  }
  @Override protected final boolean isNA_impl( int i ) { return UDP.get4(_mem,i<<2) == _NA; }
  @Override boolean set_impl(int idx, long l) {
    if( !(Integer.MIN_VALUE < l && l <= Integer.MAX_VALUE) ) return false;
    UDP.set4(_mem,idx<<2,(int)l);
    return true;
  }
  @Override boolean set_impl(int i, double d) { return false; }
  @Override boolean set_impl(int i, float f ) { return false; }
  @Override boolean setNA_impl(int idx) { UDP.set4(_mem,(idx<<2),(int)_NA); return true; }
  @Override boolean hasFloat() { return false; }
  @Override public AutoBuffer write(AutoBuffer bb) { return bb.putA1(_mem,_mem.length); }
  @Override public C4Chunk read(AutoBuffer bb) {
    _mem = bb.bufClose();
    _start = -1;
    _len = _mem.length>>2;
    assert _mem.length == _len<<2;
    return this;
  }
  @Override NewChunk inflate_impl(NewChunk nc) {
    //nothing to inflate - just copy
    nc._ds = MemoryManager.malloc8d(_len);
    nc._len = 0;
    nc._len2 = 0;
    for( int i=0; i<_len; i++ ) //use unsafe?
      if(isNA0(i))nc.addNA();
      else nc.addNum(at80(i),0);
    return nc;
  }
}

@@ -1489,17 +1489,17 @@
     nc._
-d
+l
 s = Memo
@@ -1515,17 +1515,58 @@
 .malloc8
-d
+(_len);%0A    nc._xs = MemoryManager.malloc4
 (_len);%0A

Fix in C4Chunk inflate_impl.