Class RangeTreeMatcher
java.lang.Object
com.oracle.truffle.regex.tregex.matchers.CharMatcher
com.oracle.truffle.regex.tregex.matchers.InvertibleCharMatcher
com.oracle.truffle.regex.tregex.matchers.RangeTreeMatcher
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:
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 Summary
Modifier and TypeMethodDescriptionstatic RangeTreeMatchercreate(boolean invert, int[] ranges) Constructs a newRangeTreeMatcher.intConservatively estimate the equivalent number of integer comparisons of callingCharMatcher.match(int).booleanmatch(int c) Check if a given code point matches thisCharMatcher.toString()Methods inherited from class com.oracle.truffle.regex.tregex.matchers.InvertibleCharMatcher
modifiersToString, result, result
-
Method Details
-
create
Constructs a newRangeTreeMatcher.- Parameters:
invert- seeInvertibleCharMatcher.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:CharMatcherCheck if a given code point matches thisCharMatcher.- Specified by:
matchin classCharMatcher- Parameters:
c- any code point.- Returns:
trueif the character matches.- See Also:
-
estimatedCost
public int estimatedCost()Description copied from class:CharMatcherConservatively estimate the equivalent number of integer comparisons of callingCharMatcher.match(int).- Specified by:
estimatedCostin classCharMatcher- Returns:
- the number of integer comparisons one call to
CharMatcher.match(int)is roughly equivalent to. Array loads are treated as two comparisons.
-
toString
-