(BitSet chars, String description)
| 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) { |
no test coverage detected