Exemplo n.º 1
0
 /** Appends a named column, keeping the last Vec as the response */
 public void add(String name, Vec vec) {
   assert _vecs.length == 0 || anyVec().group().equals(vec.group());
   final int len = _names.length;
   _names = Arrays.copyOf(_names, len + 1);
   _vecs = Arrays.copyOf(_vecs, len + 1);
   _keys = Arrays.copyOf(_keys, len + 1);
   _names[len] = name;
   _vecs[len] = vec;
   _keys[len] = vec._key;
 }
Exemplo n.º 2
0
 /** Removes a numbered column. */
 public Vec remove(int idx) {
   int len = _names.length;
   if (idx < 0 || idx >= len) return null;
   Vec v = _vecs[idx];
   System.arraycopy(_names, idx + 1, _names, idx, len - idx - 1);
   System.arraycopy(_vecs, idx + 1, _vecs, idx, len - idx - 1);
   System.arraycopy(_keys, idx + 1, _keys, idx, len - idx - 1);
   _names = Arrays.copyOf(_names, len - 1);
   _vecs = Arrays.copyOf(_vecs, len - 1);
   _keys = Arrays.copyOf(_keys, len - 1);
   if (v == _col0) _col0 = null;
   return v;
 }
Exemplo n.º 3
0
 /** Appends an entire Frame */
 public Frame add(Frame fr) {
   assert anyVec().group().equals(fr.anyVec().group());
   final int len0 = _names.length;
   final int len1 = fr._names.length;
   final int len = len0 + len1;
   _names = Arrays.copyOf(_names, len);
   _vecs = Arrays.copyOf(_vecs, len);
   _keys = Arrays.copyOf(_keys, len);
   System.arraycopy(fr._names, 0, _names, len0, len1);
   System.arraycopy(fr._vecs, 0, _vecs, len0, len1);
   System.arraycopy(fr._keys, 0, _keys, len0, len1);
   return this;
 }
Exemplo n.º 4
0
 @Override
 public byte[] getChunkData(int cidx) {
   if (cidx == _cidx0) return _bits0;
   if (cidx == _cidx1) return _bits1;
   assert cidx == _cidx0 + 1 || cidx == _cidx1 + 1;
   byte[] bits = _cidx0 < _cidx1 ? _bits0 : _bits1;
   if (_cidx0 < _cidx1) {
     _cidx0 = cidx;
     _coff0 = -1;
   } else {
     _cidx1 = cidx;
     _coff1 = -1;
   }
   // Read as much as the buffer will hold
   int off = 0;
   try {
     while (off < bits.length) {
       int len = _is.read(bits, off, bits.length - off);
       if (len == -1) break;
       off += len;
     }
     assert off == bits.length || _is.available() <= 0;
   } catch (IOException ioe) {
     throw new RuntimeException(ioe);
   }
   if (off == bits.length) return bits;
   // Final read is short; cache the short-read
   byte[] bits2 = (off == 0) ? null : Arrays.copyOf(bits, off);
   if (_cidx0 == cidx) _bits0 = bits2;
   else _bits1 = bits2;
   return bits2;
 }
Exemplo n.º 5
0
 static public int[] difference(int a[], int b[]) {
   int[] r = new int[a.length];
   int cnt = 0;
   for (int i=0; i<a.length; i++) {
     if (!contains(b, a[i])) r[cnt++] = a[i];
   }
   return Arrays.copyOf(r, cnt);
 }
Exemplo n.º 6
0
 @Override
 ValFrame apply(Env env, Env.StackHelp stk, AST asts[]) {
   Frame fr = stk.track(asts[1].exec(env)).getFrame();
   double frac = asts[2].exec(env).getNum();
   double nrow = fr.numRows() * frac;
   Vec vecs[] = fr.vecs();
   long[] idxs = new long[fr.numCols()];
   int j = 0;
   for (int i = 0; i < idxs.length; i++) if (vecs[i].naCnt() < nrow) idxs[j++] = i;
   Vec vec = Vec.makeVec(Arrays.copyOf(idxs, j), null, Vec.VectorGroup.VG_LEN1.addVec());
   return new ValFrame(new Frame(vec));
 }
Exemplo n.º 7
0
 public static byte [] unzipBytes(byte [] bs, Compression cmp) {
   InputStream is = null;
   int off = 0;
   try {
     switch(cmp) {
     case NONE: // No compression
       return bs;
     case ZIP: {
       ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(bs));
       ZipEntry ze = zis.getNextEntry(); // Get the *FIRST* entry
       // There is at least one entry in zip file and it is not a directory.
       if( ze != null && !ze.isDirectory() ) {
         is = zis;
         break;
       }
       zis.close();
       return bs; // Don't crash, ignore file if cannot unzip
     }
     case GZIP:
       is = new GZIPInputStream(new ByteArrayInputStream(bs));
       break;
     default:
       assert false:"cmp = " + cmp;
     }
     // If reading from a compressed stream, estimate we can read 2x uncompressed
     assert( is != null ):"is is NULL, cmp = " + cmp;
     bs = new byte[bs.length * 2];
     // Now read from the (possibly compressed) stream
     while( off < bs.length ) {
       int len = is.read(bs, off, bs.length - off);
       if( len < 0 )
         break;
       off += len;
       if( off == bs.length ) { // Dataset is uncompressing alot! Need more space...
         if( bs.length >= ValueArray.CHUNK_SZ )
           break; // Already got enough
         bs = Arrays.copyOf(bs, bs.length * 2);
       }
     }
   } catch( IOException ioe ) { // Stop at any io error
     Log.err(ioe);
   } finally {
     Utils.close(is);
   }
   return bs;
 }
Exemplo n.º 8
0
 public static int[] remove(int[] a, int i) {
   int[] tmp = Arrays.copyOf(a,a.length-1);
   System.arraycopy(a,i+1,tmp,i,tmp.length-i);
   return tmp;
 }
Exemplo n.º 9
0
 public static <T> T[] append(T[] a, T... b) {
   if( a==null ) return b;
   T[] tmp = Arrays.copyOf(a,a.length+b.length);
   System.arraycopy(b,0,tmp,a.length,b.length);
   return tmp;
 }
Exemplo n.º 10
0
 public static long[][][] append(long[][][] a, long[][] e) {
   a = Arrays.copyOf(a,a.length+1);
   a[a.length-1] = e;
   return a;
 }
Exemplo n.º 11
0
 public static double[] append(double[] a, double e) {
   a = Arrays.copyOf(a,a.length+1);
   a[a.length-1] = e;
   return a;
 }