Example #1
0
 // PREpend all of 'nc' onto the current NewChunk.  Kill nc.
 public void addr(NewChunk nc) {
   long[] tmpl = _ls;
   _ls = nc._ls;
   nc._ls = tmpl;
   int[] tmpi = _xs;
   _xs = nc._xs;
   nc._xs = tmpi;
   tmpi = _id;
   _id = nc._id;
   nc._id = tmpi;
   double[] tmpd = _ds;
   _ds = nc._ds;
   nc._ds = tmpd;
   int tmp = _sparseLen;
   _sparseLen = nc._sparseLen;
   nc._sparseLen = tmp;
   tmp = _len;
   _len = nc._len;
   nc._len = tmp;
   add(nc);
 }
Example #2
0
 private void rebalanceChunk(Vec srcVec, Chunk chk) {
   NewChunk dst = new NewChunk(chk);
   dst._len = dst._len2 = 0;
   int rem = chk._len;
   while (rem > 0 && dst._len2 < chk._len) {
     Chunk srcRaw = srcVec.chunkForRow(chk._start + dst._len2);
     NewChunk src = new NewChunk((srcRaw));
     src = srcRaw.inflate_impl(src);
     assert src._len2 == srcRaw._len;
     int srcFrom = (int) (chk._start + dst._len2 - src._start);
     // check if the result is sparse (not exact since we only take subset of src in general)
     if ((src.sparse() && dst.sparse())
         || (src._len + dst._len < NewChunk.MIN_SPARSE_RATIO * (src._len2 + dst._len2))) {
       src.set_sparse(src._len);
       dst.set_sparse(dst._len);
     }
     final int srcTo = srcFrom + rem;
     int off = srcFrom - 1;
     Iterator<NewChunk.Value> it = src.values(Math.max(0, srcFrom), srcTo);
     while (it.hasNext()) {
       NewChunk.Value v = it.next();
       final int rid = v.rowId0();
       assert rid < srcTo;
       int add = rid - off;
       off = rid;
       dst.addZeros(add - 1);
       v.add2Chunk(dst);
       rem -= add;
       assert rem >= 0;
     }
     int trailingZeros = Math.min(rem, src._len2 - off - 1);
     dst.addZeros(trailingZeros);
     rem -= trailingZeros;
   }
   assert rem == 0 : "rem = " + rem;
   assert dst._len2 == chk._len : "len2 = " + dst._len2 + ", _len = " + chk._len;
   dst.close(dst.cidx(), _fs);
 }