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