650) this.width=650, "style=" Border-bottom: #ddd 1px solid;border-left: #ddd 1px solid;background:url ("/e/u261/themes/ Default/images/word.gif ") no-repeat center;border-top: #ddd 1px solid;border-right: #ddd 1px solid;" Src= "/e/u261/ Themes/default/images/spacer.gif "width=" 411 "height=" "" alt= "spacer.gif"/> line No. 0
Line 1th (32-63), and so on.
C + + The code is as follows:
/** @file Bitmap
* @copyright Personal
* @brief Interface Header File
* @version v1.0.0
* @author Fangyuan
* @date 2015/10/20
* @note Beta version
*/
#include "iostream"
#include <math.h>
#include "Vector"
#define int_bytes sizeof(INT) //int type of the occupied bytes
#define int_bits (8*int_bytes ) //int
#define maxnum (1024*1024*1024) // Maximum number
#define shift_bit (int ) ( log (double (int_bits ))/ log (double (2))) // maximum shift number, left one equivalent to * *, which is the maximum ^shift_bit
#define MASK (int_bits-1) // varies by type of int, generally
using namespace std;
//int Bitmap[maxnum/int_bits]; array range definition exceeded
Vector <int> bitmap(maxnum/int_bits); // automatically initialized to, if not C + +, can be self-defined as list;
void set(int i)
{
//i>>shift_bit equivalent to I/int_bits,i & MASK equivalent to I%mask, the denominator of the remainder is generally ^n-1
Bitmap[i>>shift_bit] |= 1<< (i & MASK); // current bit, set to 1, then perform or operate
}
// Get line I, column J
BOOL get(int i,int J)
{
//return (Bitmap[i>>shift_bit] & 1<< (i & MASK));
return (bitmap[i] & 1<< (J & MASK));
}
int main()
{
Set (2);
Set (3);
Set (50000000);
Set (100);
Set (50);
// do not traverse by number, traverse by row, reduce traversal count
for (int i = 0; I < bitmap. size (); + +I)
{
if ( ! Bitmap [i])
{
continue;
}
for (int J = 0; J <= MASK; + +J)
{
BOOL result = get(i,J);
if (result)
{
cout << i*int_bits+J << Endl;
}
}
}
system ("Pause");
return 0;
}
This article is from the "Love Fantasy Rookie" blog, please be sure to keep this source http://3dot1415926.blog.51cto.com/8887443/1740530
Bitmap Sort Example