Java实现bitmap,判断元素是否存在?
class BitSet{
static final int N = 10000000;
int[] bitMap;
public BitSet() {
bitMap = new int[N/32+1];
}
public void add(int value) {
int index = value/32;
int offset = value%32-1;
bitMap[index] = bitMap[index] | 1<<offset;
}
public boolean isExist(int value) {
int index = value/32;
int offset = value%32-1;;
boolean flag = ((bitMap[index]>>offset)&0x01)==0x01?true:false;
return flag;
}
public void reverseDigit() {
for(int i=0;i<bitMap.length;i++) {
int temp = bitMap[i];
for(int j=0;j<32;j++) {
boolean flag = ((temp>>j)&0x01)==0x01?true:false;
if(flag) {
int data = i*32+j+1;
}
}
}
}
}