code: public void toBytesCompact(ByteBuffer buf)
    {
      Preconditions.checkState(canStoreCompact(), "Approximate histogram cannot be stored in compact form");
  
      buf.putShort((short) (-1 * size)); // use negative size to indicate compact storage
  
      final long exactCount = getExactCount();
      if (exactCount != count) {
        // use negative count to indicate approximate bins
        buf.put((byte) (-1 * (count - exactCount)));
  
        // store actual values instead of bins
        for (int i = 0; i < binCount; ++i) {
          // repeat each value bins[i] times for approximate bins
          if ((bins[i] & APPROX_FLAG_BIT) != 0) {
            for (int k = 0; k < (bins[i] & COUNT_BITS); ++k) {
              buf.putFloat(positions[i]);
            }
          }
        }
  
        // tack on min and max since they may be lost int the approximate bins
        buf.putFloat(min);
        buf.putFloat(max);
      }
  
      buf.put((byte) exactCount);
      // store actual values instead of bins
      for (int i = 0; i < binCount; ++i) {
        // repeat each value bins[i] times for exact bins
        if ((bins[i] & APPROX_FLAG_BIT) == 0) {
          for (int k = 0; k < (bins[i] & COUNT_BITS); ++k) {
            buf.putFloat(positions[i]);
          }
        }
      }
    }
docs: Returns a compact byte-buffer representation of this ApproximateHistogram object
  storing actual values as opposed to histogram bins
  
  Requires 3 + 4 * count bytes of storage with count &lt;= 127
  
  @param buf ByteBuffer to write the ApproximateHistogram to