code: public void toBytes(ByteBuffer buf)
    {
      if (canStoreCompact() && getCompactStorageSize() < getSparseStorageSize()) {
        // store compact
        toBytesCompact(buf);
      } else {
        // store sparse
        toBytesSparse(buf);
      }
    }
docs: Writes the representation of this ApproximateHistogram object to the given byte-buffer
  
  @param buf ByteBuffer to write the ApproximateHistogram to