public class DSHBitSet {
private long[] bits;
public DSHBitSet(int capacity) {
this.bits = new long[capacity / 64 + 1];
}
// ...
}
public class BitSetExample {
public static void main(String[] args) {
DSHBitSet bitSet = new DSHBitSet(10);
bitSet.set(3, true);
bitSet.set(5, true);
boolean value = bitSet.get(5);
}
}
public class BitSetOperations {
public static void main(String[] args) {
DSHBitSet bitSet1 = new DSHBitSet(10);
DSHBitSet bitSet2 = new DSHBitSet(10);
bitSet1.set(2, true);
bitSet1.set(4, true);
bitSet2.set(4, true);
bitSet2.set(6, true);
DSHBitSet andResult = DSHBitSet.and(bitSet1, bitSet2);
DSHBitSet orResult = DSHBitSet.or(bitSet1, bitSet2);
DSHBitSet xorResult = DSHBitSet.xor(bitSet1, bitSet2);
}
}
public class DSHBitSet {
private long[] bits;
public DSHBitSet(int capacity) {
this.bits = new long[capacity / 64 + 1];
}
public void set(int index, boolean value) {
int wordIndex = index / 64;
int bitIndex = index % 64;
long mask = 1L << bitIndex;
if (value) {
} else {
bits[wordIndex] &= ~mask;
}
}
public boolean get(int index) {
int wordIndex = index / 64;
int bitIndex = index % 64;
long mask = 1L << bitIndex;
return (bits[wordIndex] & mask) != 0;
}
public static DSHBitSet and(DSHBitSet set1, DSHBitSet set2) {
DSHBitSet result = new DSHBitSet(Math.max(set1.bits.length, set2.bits.length));
for (int i = 0; i < result.bits.length; i++) {
result.bits[i] = set1.bits[i] & set2.bits[i];
}
return result;
}
public static DSHBitSet or(DSHBitSet set1, DSHBitSet set2) {
DSHBitSet result = new DSHBitSet(Math.max(set1.bits.length, set2.bits.length));
for (int i = 0; i < result.bits.length; i++) {
}
return result;
}
public static DSHBitSet xor(DSHBitSet set1, DSHBitSet set2) {
DSHBitSet result = new DSHBitSet(Math.max(set1.bits.length, set2.bits.length));
for (int i = 0; i < result.bits.length; i++) {
result.bits[i] = set1.bits[i] ^ set2.bits[i];
}
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
for (long bit : bits) {
sb.append(Long.toBinaryString(bit));
}
return sb.toString();
}
}