Class KeyMappingTrie

java.lang.Object
org.aesh.readline.action.KeyMappingTrie

public class KeyMappingTrie extends Object
A trie-based data structure for efficient key sequence matching. Provides O(m) lookup complexity where m is the length of the input sequence, compared to O(n*m) for linear search where n is the number of mappings.
Author:
Ståle W. Pedersen
  • Constructor Details

    • KeyMappingTrie

      public KeyMappingTrie()
  • Method Details

    • build

      public void build(KeyAction[] mappings)
      Builds the trie from the given key mappings. This clears any existing mappings and rebuilds the trie.
      Parameters:
      mappings - the array of KeyAction mappings to index
    • clear

      public void clear()
      Clears all mappings from the trie.
    • matchSingleByte

      public KeyMappingTrie.MatchResult matchSingleByte(int code)
      Fast path for single-byte matching.
      Parameters:
      code - the single byte code point
      Returns:
      the match result
    • match

      public KeyMappingTrie.MatchResult match(int[] buffer)
      Matches the input buffer against the trie. Returns the longest matching KeyAction and whether the buffer is a prefix of longer sequences.
      Parameters:
      buffer - the input code points to match
      Returns:
      the match result containing the action and prefix information