Class PackedFileWriter

java.lang.Object
com.marksayson.deletionchecker.format.PackedFileWriter

public final class PackedFileWriter extends Object
Serializes one entity type's identifiers into a packed binary file (format v2): header, prefix index, Bloom filter, identifier offset table, identifier data, with the file's CRC32C patched into the header.

Build-time only — never invoked on the lookup path. Callers pass identifiers already sorted by unsigned bytes and deduplicated; write(java.lang.String, java.util.List<byte[]>) verifies both and rejects violations rather than producing a file that would fail mysteriously at query time.

  • Field Details

  • Method Details

    • write

      public static byte[] write(String entityType, List<byte[]> sortedIdentifiers)
      Serializes a packed file using PrefixIndex.DEFAULT_BUCKET_SIZE and DEFAULT_BLOOM_FPR.
      Parameters:
      entityType - the entity type this file holds; ASCII, 1 to 64 bytes
      sortedIdentifiers - the identifiers, already sorted by unsigned bytes and deduplicated
      Returns:
      the complete file bytes
    • write

      public static byte[] write(String entityType, List<byte[]> sortedIdentifiers, int bucketSize)
      Serializes a packed file with DEFAULT_BLOOM_FPR.
      Parameters:
      entityType - the entity type this file holds; ASCII, 1 to 64 bytes
      sortedIdentifiers - the identifiers, already sorted by unsigned bytes and deduplicated
      bucketSize - the prefix index bucket target size K; must be at least 1
      Returns:
      the complete file bytes
    • write

      public static byte[] write(String entityType, List<byte[]> sortedIdentifiers, int bucketSize, double bloomFpr)
      Serializes a packed file.
      Parameters:
      entityType - the entity type this file holds; ASCII, 1 to 64 bytes
      sortedIdentifiers - the identifiers, already sorted by unsigned bytes and deduplicated
      bucketSize - the prefix index bucket target size K; must be at least 1
      bloomFpr - the Bloom filter's target false-positive rate; >= 1 disables the filter, otherwise must be positive
      Returns:
      the complete file bytes, with the CRC32C written into the header
      Throws:
      IllegalArgumentException - if sortedIdentifiers is not strictly ascending by unsigned bytes, if entityType is not 1 to 64 ASCII bytes, if bucketSize is less than 1, or if bloomFpr is not positive