位图
#include<iostream>
#include<vector>
using namespace std;
class BitMap{
public:
BitMap(size_t range){
_bits.resize(range/32+1);
}
void set(size_t x){
int index=x>>5;
int position=x&0x31;
_bits[index]|=(1<<position);
}
void reset(size_t x){
int index=x>>5;
int position=x&0x31;
_bits[index]&=~(1<<position);
}
bool isExist(size_t x){
int index=x>>5;
int position=x&0x31;
return (_bits[index]&(1<<position))!=0;
}
private:
vector<int> _bits;
};
void test(){
BitMap bm(200);
bm.set(136);
bm.set(1);
cout<<bm.isExist(136)<<endl;
bm.reset(136);
cout<<bm.isExist(136)<<endl;
}
int main(){
test();
system("pause");
return 0;
}