EachStone::EachStone(int r, int a, bool mat[8][8]) { place.first = r; place.second = a; //マージンを計算 int x_min = 8; int x_max = -1; int y_min = 8; int y_max = -1; for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { if (mat[y][x]) { if (x < x_min)x_min = x; if (x > x_max)x_max = x; if (y < y_min)y_min = y; if (y > y_max)y_max = y; } } } margin[LEFT] = -x_min; margin[RIGHT] = 31 - x_max; margin[UP] = -y_min; margin[DOWN] = 31 - y_max; //x_min, y_minほどずらした位置からビットを立てる for (int y = y_min; y < 8; y++) { for (int x = x_min; x < 8; x++) { if (mat[y][x]) { set_bit(x - x_min, y - y_min); } } } for (int y = 0; y < 10; y++) { for (int x = 0; x < 10; x++) { if (x > 0 && y > 0 && is_set_bit(x - 1, y - 1))continue; //上下左右で隣接するマスにブロックが存在するかどうか調べる for (int t = 0; t < 4; t++) { int x_tmp = x + tx[t] - 1; int y_tmp = y + ty[t] - 1; if (x_tmp < 0 || x_tmp >= 8 || y_tmp < 0 || y_tmp >= 8)continue; if (is_set_bit(x_tmp, y_tmp)) { set_neighbor(x, y); } } } } // std::cout << r << " " << a << "\n" << get_bit_str() << std::endl; }
longint& Sievelng<longint>::previous_prime() { for (;;) { if (cursor < 0) { if (A <= 1) { resimage = 1; return resimage; } else { backward(); eratosthene(); cursor = Btable::bsize()-1; } } else cursor--; while (cursor >= 0) { if (is_set_bit(cursor)) { return image(cursor); } cursor--; } } }
void Sievelng<longint>::display(void) { cerr << "Fenetre [" << A << "," << B << "]" << endl; for (int i = 0; i <= max_bit_index; i++) if (is_set_bit(i)) cerr << setw(16) << image(i); else cerr << setw(16) << " _ "; cerr << endl; }
void Sievelgmp::display(void) { cout << "Fenetre [" << A << "," << B << "]" << endl; for (int i = 0; i <= max_bit_index; i++) if (is_set_bit(i)) cout << setw(16) << image(i); else cout << setw(16) << " _ "; cout << endl; }
void test_bitmap_is_set(opal_bitmap_t *bm) { int result=0; /* First set some bits */ test_bitmap_set(bm); is_set_bit(bm, 0); is_set_bit(bm, 1); is_set_bit(bm, 31); is_set_bit(bm, 32); result = is_set_bit(bm, 1122); TEST_AND_REPORT(result,0,"opal_bitmap_is_set_bit"); is_set_bit(bm, -33); TEST_AND_REPORT(result,0,"opal_bitmap_is_set_bit"); is_set_bit(bm, -1); TEST_AND_REPORT(result,0,"opal_bitmap_is_set_bit"); }
longint& Sievelng<longint>::next_prime() { for (;;) { // cerr << "Cursor = max_bit_index" << endl; if (cursor >= max_bit_index) { forward(); eratosthene(); cursor = 0; } else cursor++; while (cursor <= max_bit_index) { if (is_set_bit(cursor)) { // cerr << "Ok cursor = " << cursor << " image(cursor) = " // << image(cursor) << endl; return image(cursor); } else cursor++; } } }