/** * Get the BitArray for the index * * @param index * @return BitArray */ private BitArray getBitArray(long index) { int bin = getBin(index); BitArray answer = null; if (bin >= 0) { if (bin >= maxNumberOfArrays) { int overShoot = bin - maxNumberOfArrays + 1; while (overShoot > 0) { list.removeFirst(); longFirstIndex += BitArray.LONG_SIZE; list.add(new BitArray()); overShoot--; } bin = maxNumberOfArrays - 1; } answer = list.get(bin); if (answer == null) { answer = new BitArray(); list.set(bin, answer); } } return answer; }
/** * Get the boolean value at the index * * @param index * @return true/false */ public boolean getBit(long index) { boolean answer = index >= longFirstIndex; BitArray ba = getBitArray(index); if (ba != null) { int offset = getOffset(index); if (offset >= 0) { answer = ba.get(offset); return answer; } } else { // gone passed range for previous bins so assume set answer = true; } return answer; }
public long getLastSetIndex() { long result = -1; if (longFirstIndex >=0) { result = longFirstIndex; BitArray last = null; for (int lastBitArrayIndex = maxNumberOfArrays -1; lastBitArrayIndex >= 0; lastBitArrayIndex--) { last = list.get(lastBitArrayIndex); if (last != null) { result += last.length() -1; result += lastBitArrayIndex * BitArray.LONG_SIZE; break; } } } return result; } }
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { readFromStream(in); }
private void writeObject(java.io.ObjectOutputStream out) throws IOException { writeToStream(out); }
/** * Set a bit * * @param index * @param value * @return true if set */ public boolean setBit(long index, boolean value) { boolean answer = false; BitArray ba = getBitArray(index); if (ba != null) { int offset = getOffset(index); if (offset >= 0) { answer = ba.set(offset, value); } } return answer; }
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { readFromStream(in); }
private void writeObject(java.io.ObjectOutputStream out) throws IOException { writeToStream(out); }
/** * Set a bit * * @param index * @param value * @return true if set */ public boolean setBit(long index, boolean value) { boolean answer = false; BitArray ba = getBitArray(index); if (ba != null) { int offset = getOffset(index); if (offset >= 0) { answer = ba.set(offset, value); } } return answer; }
BitArray bits = new BitArray(limit + 1, true); for (int i = 1; 3 * i + 1 < limit; i++)
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { readFromStream(in); }
private void writeObject(java.io.ObjectOutputStream out) throws IOException { writeToStream(out); }
public long getLastSetIndex() { long result = -1; if (longFirstIndex >=0) { result = longFirstIndex; BitArray last = null; for (int lastBitArrayIndex = maxNumberOfArrays -1; lastBitArrayIndex >= 0; lastBitArrayIndex--) { last = list.get(lastBitArrayIndex); if (last != null) { result += last.length() -1; result += lastBitArrayIndex * BitArray.LONG_SIZE; break; } } } return result; } }
/** * Set a bit * * @param index * @param value * @return true if set */ public boolean setBit(long index, boolean value) { boolean answer = false; BitArray ba = getBitArray(index); if (ba != null) { int offset = getOffset(index); if (offset >= 0) { answer = ba.set(offset, value); } } return answer; }
/** * Get the boolean value at the index * * @param index * @return true/false */ public boolean getBit(long index) { boolean answer = index >= longFirstIndex; BitArray ba = getBitArray(index); if (ba != null) { int offset = getOffset(index); if (offset >= 0) { answer = ba.get(offset); return answer; } } else { // gone passed range for previous bins so assume set answer = true; } return answer; }
BitArray bits = new BitArray(limit + 1, true); bits[0] = false; bits[1] = false;
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { readFromStream(in); }
private void writeObject(java.io.ObjectOutputStream out) throws IOException { writeToStream(out); }
public long getLastSetIndex() { long result = -1; if (firstIndex >=0) { result = firstIndex; BitArray last = null; for (int lastBitArrayIndex = maxNumberOfArrays -1; lastBitArrayIndex >= 0; lastBitArrayIndex--) { last = list.get(lastBitArrayIndex); if (last != null) { result += last.length() -1; result += lastBitArrayIndex * BitArray.LONG_SIZE; break; } } } return result; } }
/** * Set a bit * * @param index * @param value * @return true if set */ public boolean setBit(long index, boolean value) { boolean answer = false; BitArray ba = getBitArray(index); if (ba != null) { int offset = getOffset(index); if (offset >= 0) { answer = ba.set(offset, value); } } return answer; }