Class IdDokladuCacheImpl

java.lang.Object
cz.drg.pregrouper.process.fileRead.IdDokladuCacheImpl

public final class IdDokladuCacheImpl extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
    Maximum key length.
    static final int
    62 real symbols + 1 reserved value for "absent" (padding for short keys).
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Appends entries, which must arrive in ascending key order and must continue the order established by previous calls.
    static int
    compare(long hi1, long lo1, long hi2, long lo2)
     
    static long
    encodeHalf(String s, int from)
    Encodes characters [from, from+10) into a long, treating positions past the end of the key as the reserved "absent" symbol 0.
    int
    find(long kHi, long kLo)
    Exact lookup over the FILLED range only.
    void
    forceSetMaximumCacheEntries(int maximumEntries)
    Sets the maximum number of entries that can be stored in the cache.
    get(String idDokladu)
     
     
    void
    init(long dataFileLength)
     
    boolean
     
    static void
    Resets the cache to its initial state.
    void
    Freezes the cache and releases any unused tail.
    int
     
    static int
    toDigit(char c)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LEN

      public static final int LEN
      Maximum key length. Keys may be anywhere from 0 to LEN characters.
      See Also:
    • HALF

      public static final int HALF
      See Also:
    • RADIX

      public static final int RADIX
      62 real symbols + 1 reserved value for "absent" (padding for short keys).
      See Also:
  • Constructor Details

    • IdDokladuCacheImpl

      public IdDokladuCacheImpl()
  • Method Details

    • getInstance

      public static IdDokladuCacheImpl getInstance()
    • init

      public void init(long dataFileLength)
      Parameters:
      dataFileLength - total byte length of the file being indexed; the last entry's group runs from its offset to here
    • forceSetMaximumCacheEntries

      public void forceSetMaximumCacheEntries(int maximumEntries)
      Sets the maximum number of entries that can be stored in the cache. ONLY USED FOR TESTING.
      Parameters:
      maximumEntries -
    • reset

      public static void reset()
      Resets the cache to its initial state.
    • addEntries

      public void addEntries(IdDokladuOffset[] entries)
      Appends entries, which must arrive in ascending key order and must continue the order established by previous calls. Violations throw immediately rather than corrupting the binary search — this is the check that catches a data file sorted under a non-C locale or with a case-folding collator. It only fills up to the maximum available memory, any overflow will be stored on disk and used as a fallback search option.
    • seal

      public void seal()
      Freezes the cache and releases any unused tail. Must be called before get(). Trimming matters at scale: an index built with a generous capacity estimate would otherwise hold the slack forever.
    • size

      public int size()
    • isSealed

      public boolean isSealed()
    • get

      public OffsetAndLength get(String idDokladu)
    • find

      public int find(long kHi, long kLo)
      Exact lookup over the FILLED range only.
      Returns:
      index of the key, or -(insertionPoint) - 1 if absent (same convention as Arrays.binarySearch)
    • encodeHalf

      public static long encodeHalf(String s, int from)
      Encodes characters [from, from+10) into a long, treating positions past the end of the key as the reserved "absent" symbol 0. Always runs the full 10 iterations: that right-alignment is what makes numeric comparison agree with String.compareTo.
    • toDigit

      public static int toDigit(char c)
      Returns:
      1..62 for a real alphanumeric character (0 is reserved)
    • compare

      public static int compare(long hi1, long lo1, long hi2, long lo2)