C + + implementation bitmap

Source: Internet
Author: User

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.