code: public byte[] toBytes(final ISchemaVersion schemaVersion) {
          final byte[] bytes;
          switch(type) {
              case EMPTY:
                  bytes = new byte[schemaVersion.paddingBytes(type)];
                  break;
              case EXPLICIT: {
                  final IWordSerializer serializer =
                      schemaVersion.getSerializer(type, Long.SIZE, explicitStorage.size());
  
                  final long[] values = explicitStorage.toLongArray();
                  Arrays.sort(values);
                  for(final long value : values) {
                      serializer.writeWord(value);
                  }
  
                  bytes = serializer.getBytes();
                  break;
              }
              case SPARSE: {
                  final IWordSerializer serializer =
                          schemaVersion.getSerializer(type, shortWordLength, sparseProbabilisticStorage.size());
  
                  final int[] indices = sparseProbabilisticStorage.keySet().toIntArray();
                  Arrays.sort(indices);
                  for(final int registerIndex : indices) {
                      final long registerValue = sparseProbabilisticStorage.get(registerIndex);
                      // pack index and value into "short word"
                      final long shortWord = ((registerIndex << regwidth) | registerValue);
                      serializer.writeWord(shortWord);
                  }
  
                  bytes = serializer.getBytes();
                  break;
              }
              case FULL: {
                  final IWordSerializer serializer = schemaVersion.getSerializer(type, regwidth, m);
                  probabilisticStorage.getRegisterContents(serializer);
  
                  bytes = serializer.getBytes();
                  break;
              }
              default:
                  throw new RuntimeException("Unsupported HLL type " + type);
          }
  
          final IHLLMetadata metadata = new HLLMetadata(schemaVersion.schemaVersionNumber(),
                                                        type,
                                                        log2m,
                                                        regwidth,
                                                        (int)NumberUtil.log2(explicitThreshold),
                                                        explicitOff,
                                                        explicitAuto,
                                                        !sparseOff);
          schemaVersion.writeMetadata(bytes, metadata);
  
          return bytes;
      }
docs: Serializes the HLL to an array of bytes in correspondence with the format
  of the specified schema version.
  
  @param  schemaVersion the schema version dictating the serialization format
  @return the array of bytes representing the HLL. This will never be
  <code>null</code> or empty.