package water.fvec;

import water.*;

/**
 * The empty-compression function, if all elements fit directly on UNSIGNED bytes.
 * Cannot store 0xFF, the value is a marker for N/A.
 */
public class C1Chunk extends Chunk {
  static protected final int _OFF = 0;
  static protected final long _NA = 0xFF;
  C1Chunk(byte[] bs) { _mem=bs; _start = -1; set_len(_mem.length); }
  @Override protected final long at8_impl( int i ) {
    long res = 0xFF&_mem[i+_OFF];
    if( res == _NA ) throw new IllegalArgumentException("at8 but value is missing");
    return res;
  }
  @Override protected final double atd_impl( int i ) {
    long res = 0xFF&_mem[i+_OFF];
    return (res == _NA)?Double.NaN:res;
  }
  @Override protected final boolean isNA_impl( int i ) { return (0xFF&_mem[i+_OFF]) == _NA; }
  @Override boolean set_impl(int i, long l) {
    if( !(0 <= l && l < 255) ) return false;
    _mem[i+_OFF] = (byte)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) { _mem[idx+_OFF] = (byte)_NA; return true; }
  @Override NewChunk inflate_impl(NewChunk nc) {
    nc.alloc_exponent(len());
    nc.alloc_mantissa(len());
    for( int i=0; i< len(); i++ ) {
      int res = 0xFF&_mem[i+_OFF];
      if( res == _NA ) nc.exponent()[i] = Integer.MIN_VALUE;
      else             nc.mantissa()[i] = res;
    }
    return nc;
  }
  @Override final public AutoBuffer write_impl(AutoBuffer bb) { return bb.putA1(_mem,_mem.length); }
  @Override final public C1Chunk read_impl(AutoBuffer bb) {
    _mem = bb.bufClose();
    _start = -1;
    set_len(_mem.length);
    return this;
  }
}

@@ -1194,59 +1194,65 @@
  nc.
-alloc_exponent(len());%0A    nc.alloc_mantissa(
+set_len(0);%0A    nc.set_len2(0);%0A    final int len = 
 len()
-)
 ;%0A  
@@ -1269,22 +1269,19 @@
  i=0; i%3C
- 
 len
-()
 ; i++ ) 
@@ -1347,41 +1347,15 @@
  nc.
-exponent()%5Bi%5D = Integer.MIN_VALUE
+addNA()
 ;%0A  
@@ -1382,27 +1382,21 @@
  nc.
-mantissa()%5Bi%5D = res
+addNum(res,0)
 ;%0A  

Fix bug in C1Chunk to make test pass (was fixed by Tomas in H2O).