MCPcopy Create free account
hub / github.com/antlr/codebuff / from

Method from

output/java_guava/1.4.13/SmallCharMatcher.java:91–114  ·  view source on GitHub ↗
(BitSet chars, String description)

Source from the content-addressed store, hash-verified

89
90
91 static CharMatcher from(BitSet chars, String description) {
92 // Compute the filter.
93 long filter = 0;
94 int size = chars.cardinality();
95 boolean containsZero = chars.get(0);
96 // Compute the hash table.
97 char[] table = new char[chooseTableSize(size)];
98 int mask = table.length - 1;
99 for (int c = chars.nextSetBit(0); c != -1; c = chars.nextSetBit(c + 1)) {
100 // Compute the filter at the same time.
101 filter |= 1L << c;
102 int index = smear(c) & mask;
103 while (true) {
104 // Check for empty.
105 if (table[index] == 0) {
106 table[index] = (char) c;
107 break;
108 }
109 // Linear probing.
110 index = (index + 1) & mask;
111 }
112 }
113 return new SmallCharMatcher(table, filter, containsZero, description);
114 }
115
116 @Override
117 public boolean matches(char c) {

Callers 1

precomputedPositiveMethod · 0.95

Calls 3

chooseTableSizeMethod · 0.95
smearMethod · 0.95
getMethod · 0.65

Tested by

no test coverage detected