Class RangeTreeMatcher


public final class RangeTreeMatcher extends InvertibleCharMatcher
Character range matcher that compiles to a static binary search. Example:
Given a list of ranges [[1, 2], [4, 5], [10, 11], [20, 22]], this matcher will compile to something similar to this:
 match(char c) {
     if (c < 4) {
         return 1 <= c && c <= 2;
     } else if (c > 5) {
         if (c < 10) {
             return false;
         } else if (c > 11) {
             return 20 <= c && c <= 22;
         } else {
             return true;
         }
     } else {
         return true;
     }
 }
 
  • Method Details

    • create

      public static RangeTreeMatcher create(boolean invert, int[] ranges)
      Constructs a new RangeTreeMatcher.
      Parameters:
      invert - see InvertibleCharMatcher.
      ranges - a sorted array of character ranges in the form [lower inclusive bound of range 0, higher inclusive bound of range 0, lower inclusive bound of range 1, higher inclusive bound of range 1, ...]. The array contents are not modified by this method.
      Returns:
      a new RangeTreeMatcher.
    • match

      public boolean match(int c)
      Description copied from class: CharMatcher
      Check if a given code point matches this CharMatcher.
      Specified by:
      match in class CharMatcher
      Parameters:
      c - any code point.
      Returns:
      true if the character matches.
      See Also:
      • CompilerDirectives.isPartialEvaluationConstant(Object)
    • estimatedCost

      public int estimatedCost()
      Description copied from class: CharMatcher
      Conservatively estimate the equivalent number of integer comparisons of calling CharMatcher.match(int).
      Specified by:
      estimatedCost in class CharMatcher
      Returns:
      the number of integer comparisons one call to CharMatcher.match(int) is roughly equivalent to. Array loads are treated as two comparisons.
    • toString

      public String toString()
      Overrides:
      toString in class Object