用bitmap方法,内存只需要 512M左右
#include <stdio.h>
#include <memory.h>
#define BYTESIZE 8
long long bufferlen =500000000;
char *pBuffer = new char[bufferlen];
void setbit(char * p , int posi)
{
for ( int i = 0 ; i < posi / BYTESIZE ; i++)
{
p++;
}
*p = *p | (0x01 << (posi % BYTESIZE)) ;
}
int main()
{
memset(pBuffer , 0 , bufferlen);
int arr[] = { 23,12,11,67,89,14,33};
for ( int i = 0 ; i < 7 ; i++)
{
setbit(pBuffer,arr[i]);
}
for ( int i = 0 ; i < bufferlen ; i++)
{
for ( int j = 0 ; j < BYTESIZE ; j++)
if ( (*pBuffer & (0x01 << j)) == (0x01 << j) )
printf("%d" , (i )*BYTESIZE + j);
pBuffer++;
}
return 0;
}