// Compute compressed boolean buffer private byte[] bufB(int bpv) { assert bpv == 1 || bpv == 2 : "Only bit vectors with/without NA are supported"; final int off = CBSChunk.OFF; int clen = off + CBSChunk.clen(_len2, bpv); byte bs[] = new byte[clen]; // Save the gap = number of unfilled bits and bpv value bs[0] = (byte) (((_len2 * bpv) & 7) == 0 ? 0 : (8 - ((_len2 * bpv) & 7))); bs[1] = (byte) bpv; if (_len2 != _len) { // Sparse bitvector? assert bpv == 1; // No NAs for (int i = 0; i < _len; i++) { int row = _xs[i]; bs[(row >> 3) + off] = CBSChunk.write1b(bs[(row >> 3) + off], (byte) 1, row & 7); } return bs; } // Dense bitvector int boff = 0; byte b = 0; int idx = CBSChunk.OFF; for (int i = 0; i < _len; i++) { if (bpv == 1) { assert !isNA(i); b = CBSChunk.write1b(b, (byte) _ls[i], boff); } else { byte val = isNA(i) ? CBSChunk._NA : (byte) _ls[i]; b = CBSChunk.write2b(b, val, boff); } boff += bpv; if (boff > 8 - bpv) { bs[idx] = b; boff = 0; b = 0; idx++; } } assert bs[0] == (byte) (boff == 0 ? 0 : 8 - boff); // Flush last byte if (boff > 0) bs[idx++] = b; return bs; }
// Compute compressed boolean buffer private byte[] bufB(int bpv) { assert bpv == 1 || bpv == 2 : "Only bit vectors with/without NA are supported"; final int off = CBSChunk._OFF; int clen = off + CBSChunk.clen(_len, bpv); byte bs[] = new byte[clen]; // Save the gap = number of unfilled bits and bpv value bs[0] = (byte) (((_len * bpv) & 7) == 0 ? 0 : (8 - ((_len * bpv) & 7))); bs[1] = (byte) bpv; // Dense bitvector int boff = 0; byte b = 0; int idx = CBSChunk._OFF; int j = 0; for (int i = 0; i < _len; i++) { byte val = 0; if (_id == null || (j < _id.length && _id[j] == i)) { assert bpv == 2 || !isNA2(j); val = (byte) (isNA2(j) ? CBSChunk._NA : _ls[j]); ++j; } if (bpv == 1) b = CBSChunk.write1b(b, val, boff); else b = CBSChunk.write2b(b, val, boff); boff += bpv; if (boff > 8 - bpv) { assert boff == 8; bs[idx] = b; boff = 0; b = 0; idx++; } } assert j == sparseLen(); assert bs[0] == (byte) (boff == 0 ? 0 : 8 - boff) : "b[0] = " + bs[0] + ", boff = " + boff + ", bpv = " + bpv; // Flush last byte if (boff > 0) bs[idx] = b; return bs; }