Record Class BulkCompressor

java.lang.Object
java.lang.Record
com.dannemann.stringcompressor.bulk.BulkCompressor
Record Components:
compressor - The AsciiCompressor used to compress each string.
destination - The destination array where compressed data will be stored.

public record BulkCompressor(AsciiCompressor compressor, byte[][] destination) extends Record

Utility for compressing batches of strings using a provided AsciiCompressor and storing the compressed results in a pre-allocated destination array.

Note: This is a "lower-level" utility. See class ManagedBulkCompressor for a higher-level abstraction of an automated batching process.

This class is designed for bulk operations where multiple strings (as String[], byte[][], or List<String>) need to be compressed efficiently and stored at specified positions in the destination array. Compression is performed in parallel for better performance.

The destination array must be large enough to accommodate the compressed data starting from the specified index provided in each method call.

See Also:
  • Constructor Details

    • BulkCompressor

      public BulkCompressor(AsciiCompressor compressor, byte[][] destination)
      Creates an instance of a BulkCompressor record class.
      Parameters:
      compressor - the value for the compressor record component
      destination - the value for the destination record component
  • Method Details

    • bulkCompress

      public void bulkCompress(byte[][] source, int destinationStart, TriConsumer<Integer,byte[],byte[]> callback)

      Compress a batch of strings and add them to the destination array starting at the specified index. A callback function is executed after each compression iteration (useful for logging and debugging).

      The arguments passed to the callback function are the index, the original string, and its compressed form. Note that this is executed in parallel, so, don't expect a sequential index in the callback.

      Parameters:
      source - The batch of strings to be compressed.
      destinationStart - The index at which elements will start being added to the destination array.
      callback - A function that is called after each item is compressed and added to the destination array.
    • bulkCompress

      public void bulkCompress(String[] source, int destinationStart, TriConsumer<Integer,String,byte[]> callback)
    • bulkCompress

      public void bulkCompress(List<String> source, int destinationStart, TriConsumer<Integer,String,byte[]> callback)
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • compressor

      public AsciiCompressor compressor()
      Returns the value of the compressor record component.
      Returns:
      the value of the compressor record component
    • destination

      public byte[][] destination()
      Returns the value of the destination record component.
      Returns:
      the value of the destination record component