public int getSize() { int size = 14; // size of nbHash,hashType, vectorSize, compress if (compress) { size += bitmap.getSizeInBytes(); } else { try { size += getBitSet().toLongArray().length * 8; } catch (IOException e) { throw new RuntimeException(e); } } return size; }
@Override public void write(DataOutput out) throws IOException { out.writeInt(blockletNo); out.writeInt(this.nbHash); out.writeByte(this.hashType); out.writeInt(this.vectorSize); out.writeBoolean(compress); BitSet bits = getBitSet(); if (!compress) { byte[] bytes = bits.toByteArray(); out.writeInt(bytes.length); out.write(bytes); } else { RoaringBitmap bitmap = new RoaringBitmap(); int length = bits.cardinality(); int nextSetBit = bits.nextSetBit(0); for (int i = 0; i < length; ++i) { bitmap.add(nextSetBit); nextSetBit = bits.nextSetBit(nextSetBit + 1); } bitmap.serialize(out); } }