BitArray.java revision 7e3fa36d69ffee874dd364b8e3d9aa3cab9a273b
/*
* Copyright 2007 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* <p>A simple, fast array of bits, represented compactly by an array of ints internally.</p>
*
* @author Sean Owen
*/
public final class BitArray {
private int[] bits;
private int size;
public BitArray() {
this.size = 0;
this.bits = new int[1];
}
}
// For testing only
}
public int getSize() {
return size;
}
public int getSizeInBytes() {
}
private void ensureCapacity(int size) {
}
}
/**
* @param i bit to get
* @return true iff bit i is set
*/
public boolean get(int i) {
}
/**
* Sets bit i.
*
* @param i bit to set
*/
public void set(int i) {
}
/**
* Flips bit i.
*
* @param i bit to set
*/
public void flip(int i) {
}
/**
* @param from first bit to check
* @return index of first bit that is set, starting from the given index, or size if none are set
* at or beyond this given index
* @see #getNextUnset(int)
*/
public int getNextSet(int from) {
return size;
}
// mask off lesser bits first
while (currentBits == 0) {
return size;
}
}
}
/**
* @see #getNextSet(int)
*/
public int getNextUnset(int from) {
return size;
}
// mask off lesser bits first
while (currentBits == 0) {
return size;
}
}
}
/**
* Sets a block of 32 bits, starting at bit i.
*
* @param i first bit to set
* @param newBits the new value of the next 32 bits. Note again that the least-significant bit
* corresponds to bit i, the next-least-significant to i+1, and so on.
*/
}
/**
* Sets a range of bits.
*
* @param start start of range, inclusive.
* @param end end of range, exclusive
*/
throw new IllegalArgumentException();
}
return;
}
end--; // will be easier to treat this as the last actually set bit -- inclusive
int mask;
mask = -1;
} else {
mask = 0;
mask |= 1 << j;
}
}
}
}
/**
* Clears all bits (sets to false).
*/
public void clear() {
for (int i = 0; i < max; i++) {
bits[i] = 0;
}
}
/**
* Efficient method to check if a range of bits is set, or not set.
*
* @param start start of range, inclusive.
* @param end end of range, exclusive
* @param value if true, checks that bits in range are set, otherwise checks that they are not set
* @return true iff all bits are set or not set in range, according to value argument
* @throws IllegalArgumentException if end is less than or equal to start
*/
throw new IllegalArgumentException();
}
return true; // empty range matches
}
end--; // will be easier to treat this as the last actually set bit -- inclusive
int mask;
mask = -1;
} else {
mask = 0;
mask |= 1 << j;
}
}
// Return false if we're looking for 1s and the masked bits[i] isn't all 1s (that is,
// equals the mask, or we're looking for 0s and the masked portion is not all 0s
return false;
}
}
return true;
}
if (bit) {
}
size++;
}
/**
* Appends the least-significant bits, from value, in order from most-significant to
* least-significant. For example, appending 6 bits from 0x000001E will append the bits
* 0, 1, 1, 1, 1, 0 in that order.
*/
throw new IllegalArgumentException("Num bits must be between 0 and 32");
}
}
}
for (int i = 0; i < otherSize; i++) {
}
}
throw new IllegalArgumentException("Sizes don't match");
}
// The last byte could be incomplete (i.e. not have 8 bits in
// it) but there is no problem since 0 XOR 0 == 0.
}
}
/**
*
* @param bitOffset first bit to start writing
* @param array array to write into. Bytes are written most-significant byte first. This is the opposite
* of the internal representation, which is exposed by {@link #getBitArray()}
* @param offset position in array to start writing
* @param numBytes how many bytes to write
*/
for (int i = 0; i < numBytes; i++) {
int theByte = 0;
for (int j = 0; j < 8; j++) {
}
bitOffset++;
}
}
}
/**
* @return underlying array of ints. The first element holds the first 32 bits, and the least
* significant bit is bit 0.
*/
public int[] getBitArray() {
return bits;
}
/**
* Reverses all bits in the array.
*/
public void reverse() {
// reverse all int's first
for (int i = 0; i < oldBitsLen; i++) {
long x = (long) bits[i];
x = ((x >> 1) & 0x55555555L) | ((x & 0x55555555L) << 1);
x = ((x >> 2) & 0x33333333L) | ((x & 0x33333333L) << 2);
x = ((x >> 4) & 0x0f0f0f0fL) | ((x & 0x0f0f0f0fL) << 4);
x = ((x >> 8) & 0x00ff00ffL) | ((x & 0x00ff00ffL) << 8);
x = ((x >> 16) & 0x0000ffffL) | ((x & 0x0000ffffL) << 16);
}
// now correct the int's if the bit size isn't a multiple of 32
int mask = 1;
}
for (int i = 1; i < oldBitsLen; i++) {
}
}
}
}
for (int i = 0; i < size; i++) {
if ((i & 0x07) == 0) {
}
}
}
}