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

Method from

corpus/java/training/guava/base/SmallCharMatcher.java:87–110  ·  view source on GitHub ↗
(BitSet chars, String description)

Source from the content-addressed store, hash-verified

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