Class CharClass

java.lang.Object
org.aesh.readline.fuzzy.CharClass

public final class CharClass extends Object
Character classification and bonus matrix for fuzzy matching.

This is a direct port of fzf's character classification system. Characters are classified into one of 7 categories, and a precomputed bonusMatrix[prevClass][curClass] lookup table provides the bonus score for matching at each position based on the transition between adjacent character classes.

The ASCII fast path (classOfAscii(int)) uses a precomputed 128-entry lookup table for O(1) classification of ASCII characters.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static short
    bonus(int prevClass, int curClass)
    Look up the bonus for a character at a given position based on the previous and current character classes.
    static short
    bonusAt(int[] input, int idx, FuzzyScheme scheme)
    Calculate the bonus for matching at a given position in the input.
    static int
    classOf(int codePoint)
    Classify a character (code point).
    static void
    init(FuzzyScheme scheme)
    Initialize the bonus matrix for a given scheme.

    Methods inherited from class Object

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

  • Method Details

    • init

      public static void init(FuzzyScheme scheme)
      Initialize the bonus matrix for a given scheme. Must be called before using the bonus matrix.
      Parameters:
      scheme - the scoring scheme to use
    • classOf

      public static int classOf(int codePoint)
      Classify a character (code point). Uses the fast ASCII lookup table for code points 0-127, falls back to Unicode classification for non-ASCII.
      Parameters:
      codePoint - the character code point
      Returns:
      the character class constant
    • bonus

      public static short bonus(int prevClass, int curClass)
      Look up the bonus for a character at a given position based on the previous and current character classes.
      Parameters:
      prevClass - the class of the preceding character
      curClass - the class of the current character
      Returns:
      the bonus score
    • bonusAt

      public static short bonusAt(int[] input, int idx, FuzzyScheme scheme)
      Calculate the bonus for matching at a given position in the input.
      Parameters:
      input - the input code points
      idx - the position in the input
      scheme - the scoring scheme (for initialCharClass)
      Returns:
      the bonus score