0001 /****************************************************************************************** 0002 * 测试位图 0003 ******************************************************************************************/ 0004 int testBitmap ( int n ) { 0005 bool* B = new bool[n]; memset ( B, 0, n * sizeof ( bool ) ); //常规位图,创建后随即O(n)时间初始化 0006 Bitmap M ( n ); 0007 for ( int i = 0; i < 9 * n; i++ ) { 0008 Rank k = dice ( n ); 0009 printf ( "set(%d) ...", k ); //set(k) 0010 B[k] = true; M.set ( k ); 0011 printf ( "done\n CRC: " ); 0012 for ( int j = 0; j < n; j++ ) 0013 printf ( "%c", B[j] == M.test ( j ) ? ' ' : '!' ); 0014 printf ( "\n B[]: " ); 0015 for ( int j = 0; j < n; j++ ) 0016 printf ( "%c", B[j] ? 'x' : '.' ); 0017 printf ( "\n M[]: " ); 0018 for ( int j = 0; j < n; j++ ) 0019 printf ( "%c", M.test ( j ) ? 'x' : '.' ); 0020 printf ( "\n\n\n" ); 0021 } 0022 delete [] B; 0023 return 0; 0024 } 0025 0026 /****************************************************************************************** 0027 * 测试位图 0028 ******************************************************************************************/ 0029 int main ( int argc, char* argv[] ) { 0030 if ( 2 > argc ) { printf ( "Usage: %s <size of test>\a\a\n", argv[0] ); return 1; } 0031 srand ( ( unsigned int ) time ( NULL ) ); //设置随机种子 0032 return testBitmap ( atoi ( argv[1] ) ); //启动测试 0033 }