#pragma once#include <vector>class bitmap{public:bitmap (): _size (0) {}void resize (size _t size) {_a.resize ((size>>5) + 1);} Void set (size_t x) {size_t index = x>>5;size_t n = x % 32;_a[index] |= (1<<n); ++_size;} Void reset (size_t x) {size_t index = x>>5;size_t n = x % 32;_a[index] &= (~ (1<<n));--_size;} Bool test (size_t x) {size_t index = x>>5;size_t n = x % 32;return _a[index] & (1<<n);} Size_t size () {return _size;} protected:vector<size_t> _a;size_t _size;}; Void bitmaptest () {Bitmap bitmap;bitmap. Resize (+); bitmap. Set (All); bitmap. Set (1); bitmap. Set (4); bitmap. Set (;cout<<) "65?" <<bitmap. Test (+) <<endl;cout<< "1?" <<bitmap. Test (1) <<endl;cout<< "4?" <<Bitmap. Test (4) <<endl;cout<< "45?" <<bitmap. Test <<endl;cout<< "25?" <<bitmap. Test <<endl;cout<<endl<< Reset (<<endl;bitmap). Reset (;cout<<) "65?" <<bitmap. Test <<endl;cout<<endl<< "Size:" <<bitmap. Size () <<endl;}
#include <iostream>using namespace std;//#include "HashTablesBucket.h" #include "BitMap.h" int main () {//testdic ( );//test (); Bitmaptest (); return 0;}
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/82/77/wKioL1dWRp-hvgAdAAB27qvfZ58467.png-wh_500x0-wm_3 -wmp_4-s_3767853985.png "title=" Bitmaptest.png "alt=" Wkiol1dwrp-hvgadaab27qvfz58467.png-wh_50 "/>
This article is from the "zgw285763054" blog, make sure to keep this source http://zgw285763054.blog.51cto.com/11591804/1786883
C + + implementation bitmap