Class TagKeyCache

java.lang.Object
htsjdk.samtools.cram.structure.TagKeyCache

public final class TagKeyCache extends Object
Caches the per-tag-ID metadata that is invariant across all records in a slice.

In CRAM, each tag is identified by a 3-byte ID (2 bytes tag name + 1 byte type) packed into an int. The tag ID dictionary in the compression header defines the small set of unique tag IDs used in a slice (typically 5-20). This class pre-computes and caches the derived String keys, binary tag codes, and type characters so they can be reused across millions of records without repeated allocation.

Internally uses parallel arrays with linear scan lookup, which is optimal for the small number of entries typical in CRAM slices (fits in 1-2 cache lines).

  • Constructor Details

    • TagKeyCache

      public TagKeyCache(byte[][][] tagIDDictionary)
      Creates a TagKeyCache from a tag ID dictionary.
      Parameters:
      tagIDDictionary - the tag ID dictionary from the compression header, where each entry in the outer array is a combination of tag IDs (as 3-byte arrays) that appear together on records
  • Method Details

    • get

      public TagKeyCache.TagKeyInfo get(int id)
      Looks up the cached metadata for the given 3-byte tag ID.
      Parameters:
      id - the tag ID as a packed int (2 bytes name + 1 byte type)
      Returns:
      the cached metadata, or null if the ID is not in the cache