jdk.nashorn.internal.runtime.regexp.joni.BitSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nashorn Show documentation
Show all versions of nashorn Show documentation
A maven release for nashorn. Changed nothing, just put it to maven.
/*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package jdk.nashorn.internal.runtime.regexp.joni;
@SuppressWarnings("javadoc")
public final class BitSet {
static final int BITS_PER_BYTE = 8;
public static final int SINGLE_BYTE_SIZE = (1 << BITS_PER_BYTE);
private static final int BITS_IN_ROOM = 4 * BITS_PER_BYTE;
static final int BITSET_SIZE = (SINGLE_BYTE_SIZE / BITS_IN_ROOM);
static final int ROOM_SHIFT = log2(BITS_IN_ROOM);
final int[] bits = new int[BITSET_SIZE];
private static final int BITS_TO_STRING_WRAP = 4;
@Override
public String toString() {
final StringBuilder buffer = new StringBuilder();
buffer.append("BitSet");
for (int i=0; i>> ROOM_SHIFT] & bit(pos)) != 0;
}
public void set(final int pos) {
bits[pos >>> ROOM_SHIFT] |= bit(pos);
}
public void clear(final int pos) {
bits[pos >>> ROOM_SHIFT] &= ~bit(pos);
}
public void clear() {
for (int i=0; i>>= 1) != 0) {
log++;
}
return log;
}
}