位图
2016-03-27 14:41
288 查看
位图主要用来处理海量数据问题
//数据必须集中在一个范围内,且不能存负数 class BitMap//将数据存储在对应的位,用位来存储数据 { public: BitMap(size_t len) { int size = len >> 5; if (len % 32) _array.resize(size + 1); else _array.resize(size); } BitMap(size_t minLen, size_t maxLen)//如果用这种,求下标时(num-minLen)/32 { int size = (maxLen-minLen+1) >> 5; if ((maxLen - minLen + 1 )% 32) _array.resize(size + 1); else _array.resize(size); } void Set(size_t num) { size_t index = num >> 5; size_t count = num % 32; _array[index] |= (1 << count);//将_array[index]第count位置为1,此处存储和大小端有关系 } void ReSet(size_t num) { size_t index = num >> 5; size_t count = num % 32; _array[index] &= (!(1 << count));//将_array[index]第count位置为1,此处存储和大小端有关系 } bool Test(size_t num) { size_t index = num >> 5; size_t count = num % 32; return _array[index] &(1 << count); } private: vector<int> _array;//用vector<char>不能存储相同的数,有限制,因为它只有0,1两个不同的位 }; void Test2() { BitMap bm(100); bm.Set(0); bm.Set(100); bm.Set(9); bm.Set(4); bm.Set(77); bm.Set(6); cout << bm.Test(0) << " " << bm.Test(10) << " " << bm.Test(77)<<endl; }
相关文章推荐
- C#实现位图转换成图标的方法
- C++实现位图排序实例
- C语言实现的bitmap位图代码分享
- 数据结构之位图(bitmap)详解
- 转:抗锯齿方法两种(其一:paint.setAntiAlias(ture);paint.setBitmapFilter(true))
- 位图索引 btree索引
- 位图排序算法的一个实践
- IOS处理位图
- 学习opencv——图像颜色分布直方图
- 学习opencv——sift与suft的应用
- vc 将位图多余部分变为透明
- 2.1-2.4.文件读取时间测试
- (nehe教程)不使用auxDIBImageLoad,加载bmp文件
- 对图像进行FFT
- 数字图像处理,bmp位图灰度化
- 对图像进行FFT
- Android开发之网络图片查看方法BitmapFactory.decodeStream()学习01
- Bmp学习
- AS3.0视觉特效:像素风格图像切换
- 位图法