std::vector<vec2> find_ships(vec2 tl, vec2 br) { std::vector<vec2> ret; int w = br.x - tl.x; int h = br.y - tl.y; int cell_width = w / 10; int cell_height = h / 10; vec2 cell = {cell_width, cell_height}; vec2 start = tl + (cell * 0.5); vec2 cc = start; for(int i=0;i<10;++i) { cc.x = start.x; for(int j=0;j<10;++j) { if(check_cell(cc,cell)) { vec2 s = {j,i}; ret.push_back(s); } pixels[((int)cc.y)*width+(int)cc.x].r = 255; pixels[((int)cc.y)*width+(int)cc.x].g = 25; pixels[((int)cc.y)*width+(int)cc.x].b = 25; cc.x += cell.x; } cc.y += cell.y; } return ret; }
void run(const Pos& p0, const bool hard_blocked[MAP_W][MAP_H], Los_result out[MAP_W][MAP_H]) { for (int x = 0; x < MAP_W; ++x) { for (int y = 0; y < MAP_H; ++y) { Los_result& los = out[x][y]; los.is_blocked_hard = true; los.is_blocked_by_drk = false; } } const Rect r = get_fov_rect(p0); for (int x = r.p0.x; x <= r.p1.x; ++x) { for (int y = r.p0.y; y <= r.p1.y; ++y) { out[x][y] = check_cell(p0, {x, y}, hard_blocked); } } out[p0.x][p0.y].is_blocked_hard = false; }
int TestObSSTableScanner::test_single_query_helper(const ObRange& range, const int32_t row_start_index , const int32_t row_expect_count, const int32_t column_count ) { ObScanParam scan_param; scan_param.set(SSTableBuilder::table_id, table_name, range); ObCellInfo** const cell_infos = sstable_builder_.get_cell_infos(); for (int64_t i = 0; i < column_count; ++i) { scan_param.add_column(cell_infos[0][i].column_id_); } int err = scanner_.set_scan_param(scan_param, &sstable_reader_, GFactory::get_instance().get_block_cache(), GFactory::get_instance().get_block_index_cache() ); if (err) return err; // check result int64_t row_index = 0; int64_t col_index = 0; int64_t total = 0; ObCellInfo* cur_cell = NULL; bool is_row_changed = false; bool first_row = true; while (OB_SUCCESS == scanner_.next_cell()) { err = scanner_.get_cell(&cur_cell, &is_row_changed); EXPECT_EQ(0, err); EXPECT_NE((ObCellInfo*) NULL, cur_cell); if (is_row_changed) { if (col_index > 0) EXPECT_EQ(column_count, col_index+1); // reset column col_index = 0; if (!first_row) ++row_index; if (first_row) first_row = false; } else { ++col_index; } check_cell(cell_infos[row_index + row_start_index][col_index], *cur_cell); ++total; } int row_count = 0; if (first_row) row_count = 0; else row_count = static_cast<int32_t>(row_index + 1); EXPECT_EQ(row_count , row_expect_count); EXPECT_EQ(row_count * column_count, total); return 0; }
void neighbors_test () { for (j=0; j<number_of_rows; j++) { for (k=0; k<32; k++){ int derp=check_cell( j, k, is_world_calc); printf("%i", derp); } printf("\n"); } printf("-------\n"); }
void on_tick() { // Function to be called once per tick. // Every tick we should go through the world and run check_cell on each cell in // world_write to determine the new value of world_calc's cells // Then, we set world_write's values equal to world_calc's new value and display them for (j=0; j<number_of_rows; j++) { for (k=0; k<32; k++){ write_cell( j, k, check_cell( j, k, is_world_calc) ); } } display_world(); is_world_calc = !(is_world_calc); }
bool check_node(b_tree_node *n) { b_tree_cell *it = n->header; int count = 0; while (it != nullptr) { if (it->next && it->key > it->next->key) { return false; } if (it->child && it->child->pnode != n) { return false; } if (!check_cell(it)) { return false; } count++; it = it->next; } return n->size == count && n->size <= B_TREE_ORDER && (root == n || n->size >= (B_TREE_ORDER + 1) / 2); }
TEST_F(TestObSSTableScanner, test_query_case_sync_read) { int err = OB_SUCCESS; ObCellInfo** const cell_infos = sstable_builder_.get_cell_infos(); ObRange range; range.table_id_ = SSTableBuilder::table_id; ///range.start_key_ = cell_infos[row_start_index][0].row_key_;//do not set start key ObBorderFlag border_flag; char* start_key = (char*)"row_key_0"; border_flag.set_inclusive_start(); border_flag.set_inclusive_end(); range.start_key_.assign_ptr(start_key, static_cast<int32_t>(strlen(start_key))); //end key range.end_key_ = cell_infos[10][0].row_key_; //end key range.border_flag_ = border_flag; ObScanParam scan_param; scan_param.set(SSTableBuilder::table_id, table_name, range); scan_param.set_is_result_cached(false); scan_param.set_read_mode(ObScanParam::SYNCREAD); scan_param.add_column((uint64_t)0); err = scanner_.set_scan_param(scan_param, &sstable_reader_, GFactory::get_instance().get_block_cache(), GFactory::get_instance().get_block_index_cache() ); EXPECT_EQ(0, err); // check result int64_t row_expect_count = 11; int64_t row_start_index = 0; int64_t row_index = 0; int64_t col_index = 0; int64_t column_count = SSTableBuilder::COL_NUM; int64_t total = 0; ObCellInfo* cur_cell = NULL; bool is_row_changed = false; bool first_row = true; while (OB_SUCCESS == scanner_.next_cell()) { err = scanner_.get_cell(&cur_cell, &is_row_changed); EXPECT_EQ(0, err); EXPECT_NE((ObCellInfo*) NULL, cur_cell); if (is_row_changed) { if (col_index > 0) EXPECT_EQ(column_count, col_index+1); // reset column col_index = 0; if (!first_row) ++row_index; if (first_row) first_row = false; } else { ++col_index; } check_cell(cell_infos[row_index + row_start_index][col_index], *cur_cell); ++total; } int row_count = 0; if (first_row) row_count = 0; else row_count = static_cast<int32_t>(row_index + 1); EXPECT_EQ(row_count , row_expect_count); EXPECT_EQ(row_count * column_count, total); }
int main(int argc, char *argv[]) { //sgenrand(time(NULL)); int k, curr_pos, check; int chunk; /* Repeat experiment in chunks. */ srand(SEED); printf("# Info: $Header: /home/ma/p/pruess/.cvsroot/manna_range/dmitry_20151021/manna_stack_clean_edited.c,v 1.2 2015/10/21 11:37:00 pruess Exp $\n"); preamble(argc, argv); PRINT_PARAM(SEED, "%lu"); PRINT_PARAM(LENGTH, "%lu"); PRINT_PARAM(DROP_LOCATION, "%lu"); PRINT_PARAM(total_malloced, "%lli"); printf("# Info: Expected avalanche size: <s>(x) = 1+(1/2) (<s>(x+1)+<s>(x-1)), BC <s>(0)=0, <s>(L+1)=0, solved by <s>(x)=(L+1-x)x/2.\n"); printf("# Info: Here L=LENGTH=%lu and x=DROP_LOCATION+1=%lu, so expect %g\n", LENGTH, DROP_LOCATION+1, ((double)(DROP_LOCATION+1))*((double)(LENGTH-DROP_LOCATION))/2.); for (chunk=1; ((chunk<=NUM_CHUNKS) || (NUM_CHUNKS<0)); chunk++) { MOMENTS_INIT(size); for (drop = 0; drop < N_ROLLS; drop++) { // big droppping cycle size=0; /* printf("(%i.)", drop); for(k = 0; k<LENGTH; k++) { printf("\%i", lattice[k]); } printf("\n"); */ #if (1) if(check_cell(DROP_LOCATION) == 0) { lattice[DROP_LOCATION] = 1; } else { stack_push(DROP_LOCATION); stack_push(DROP_LOCATION); lattice[DROP_LOCATION] = 0; } /* If validated, optimse by turning stack operations into macros, * optime random number drawing (rather than having doubles in the tree * have integers there and draw an integer to compare against), * optimise the shuffling of particles. * * I have added MOMENT macros for size. */ while(stack_used != 0) { curr_pos = stack_pop(); /* This code with the "check" looks clumsy. I suppose * you are "following through" topplings? I would think * there is no point doing this later. Anyway, we validate * this code and take it from there. */ do { curr_pos = move_ball(curr_pos); if(curr_pos >= LENGTH || curr_pos < 0) { check = 0 ; } /* Why not just "else" instead of the "if"? */ if(curr_pos < LENGTH && curr_pos >= 0) { check = check_cell(curr_pos); if (check == 1) { stack_push(curr_pos); } else { check = 0; } } }while(check != 0); }/* end of while(stack_used != 0) look */ #endif #if (0) { int npos; #define PUSH(a) stack[stack_used++]=(a) #define POP(a) (a)=stack[--stack_used] if (lattice[DROP_LOCATION]++==1) { PUSH(DROP_LOCATION); while(stack_used) { size++; POP(curr_pos); do { lattice[curr_pos]-=2; npos=curr_pos+ ( (rand()>RAND_MAX/2) ? 1 : -1); if ((npos>=0) && (npos<LENGTH)) { if (lattice[npos]++==1) {PUSH(npos);} } if ((npos>=0) && (npos<LENGTH)) { if (lattice[npos]++==1) {PUSH(npos);} } } while (lattice[curr_pos]>1); } } } #endif //printf("size is %i\n", size); MOMENTS(size,size); } /* end of iterations loop */ MOMENTS_OUT(size); } /* chunk */ }
static int check_centering(double a, double b, double c, double al, double be, double ga, LatticeType latt, char cen, char ua, gsl_rng *rng) { UnitCell *cell, *cref; UnitCell *n; UnitCellTransformation *t; int fail = 0; int i; double asx, asy, asz; double bsx, bsy, bsz; double csx, csy, csz; double ax, ay, az; double bx, by, bz; double cx, cy, cz; STATUS(" ---------------> " "Checking %s %c (ua %c) %5.2e %5.2e %5.2e %5.2f %5.2f %5.2f\n", str_lattice(latt), cen, ua, a, b, c, al, be, ga); cref = cell_new_from_parameters(a, b, c, deg2rad(al), deg2rad(be), deg2rad(ga)); cell_set_lattice_type(cref, latt); cell_set_centering(cref, cen); cell_set_unique_axis(cref, ua); cell = cell_rotate(cref, random_quaternion(rng)); if ( cell == NULL ) return 1; cell_free(cref); check_cell(cell, "Input"); n = uncenter_cell(cell, &t); if ( n != NULL ) { STATUS("Transformation was:\n"); tfn_print(t); if ( check_cell(n, "Output") ) fail = 1; if ( !fail ) cell_print(n); } else { fail = 1; } cell_get_reciprocal(cell, &asx, &asy, &asz, &bsx, &bsy, &bsz, &csx, &csy, &csz); cell_get_cartesian(n, &ax, &ay, &az, &bx, &by, &bz, &cx, &cy, &cz); fesetround(1); /* Round towards nearest */ for ( i=0; i<100; i++ ) { signed int h, k, l; double x, y, z; double nh, nk, nl; double dh, dk, dl; int f = 0; do { h = gsl_rng_uniform_int(rng, 30); k = gsl_rng_uniform_int(rng, 30); l = gsl_rng_uniform_int(rng, 30); } while ( forbidden_reflection(cell, h, k, l) ); x = h*asx + k*bsx + l*csx; y = h*asy + k*bsy + l*csy; z = h*asz + k*bsz + l*csz; nh = x*ax + y*ay + z*az; nk = x*bx + y*by + z*bz; nl = x*cx + y*cy + z*cz; dh = nh - lrint(nh); dk = nk - lrint(nk); dl = nl - lrint(nl); if ( fabs(dh) > 0.1 ) f++; if ( fabs(dk) > 0.1 ) f++; if ( fabs(dl) > 0.1 ) f++; if ( f ) { STATUS("Centered %3i %3i %3i -> " "Primitive %7.2f %7.2f %7.2f\n", h, k, l, nh, nk, nl); fail = 1; } } cell_get_reciprocal(n, &asx, &asy, &asz, &bsx, &bsy, &bsz, &csx, &csy, &csz); cell_get_cartesian(cell, &ax, &ay, &az, &bx, &by, &bz, &cx, &cy, &cz); for ( i=0; i<100; i++ ) { signed int h, k, l; double x, y, z; double nh, nk, nl; double dh, dk, dl; int f = 0; long int ih, ik, il; h = gsl_rng_uniform_int(rng, 30); k = gsl_rng_uniform_int(rng, 30); l = gsl_rng_uniform_int(rng, 30); x = h*asx + k*bsx + l*csx; y = h*asy + k*bsy + l*csy; z = h*asz + k*bsz + l*csz; nh = x*ax + y*ay + z*az; nk = x*bx + y*by + z*bz; nl = x*cx + y*cy + z*cz; dh = nh - lrint(nh); dk = nk - lrint(nk); dl = nl - lrint(nl); if ( fabs(dh) > 0.1 ) f++; if ( fabs(dk) > 0.1 ) f++; if ( fabs(dl) > 0.1 ) f++; ih = lrint(nh); ik = lrint(nk); il = lrint(nl); if ( forbidden_reflection(cell, ih, ik, il) ) { STATUS("Primitive %3i %3i %3i -> " "Centered %3li %3li %3li, " "which is forbidden\n", h, k, l, ih, ik, il); fail = 1; } if ( f ) { STATUS("Primitive %3i %3i %3i -> " "Centered %7.2f %7.2f %7.2f\n", h, k, l, nh, nk, nl); fail = 1; } } return fail; }
int main(int argc, char** argv) { const int32_t MOCK_SERVER_LISTEN_PORT = 8888; MockClient client; ObServer dst_host; const char* dst_addr = "localhost"; dst_host.set_ipv4_addr(dst_addr, MOCK_SERVER_LISTEN_PORT); client.init(dst_host); // init cell info static const int64_t ROW_NUM = 1; static const int64_t COL_NUM = 10; ObCellInfo cell_infos[ROW_NUM][COL_NUM]; char row_key_strs[ROW_NUM][50]; uint64_t table_id = 10; // init cell infos for (int64_t i = 0; i < ROW_NUM; ++i) { sprintf(row_key_strs[i], "row_key_%08ld", i); for (int64_t j = 0; j < COL_NUM; ++j) { cell_infos[i][j].table_id_ = table_id; cell_infos[i][j].row_key_.assign(row_key_strs[i], strlen(row_key_strs[i])); //cell_infos[i][j].op_info_.set_sem_ob(); cell_infos[i][j].column_id_ = j + 1; cell_infos[i][j].value_.set_int(1000 + i * COL_NUM + j); } } // scan memtable ObScanner scanner; ObScanParam scan_param; //ObOperateInfo op_info; ObString table_name; ObRange range; const int64_t version = 999; range.start_key_ = cell_infos[0][0].row_key_; range.end_key_ = cell_infos[ROW_NUM - 1][0].row_key_; range.border_flag_.set_inclusive_start(); range.border_flag_.set_inclusive_end(); scan_param.set(table_id, table_name, range); //scan_param.set_timestamp(version); //scan_param.set_is_read_frozen_only(false); ObVersionRange version_range; version_range.start_version_ = version; version_range.end_version_ = version; version_range.border_flag_.set_inclusive_start(); version_range.border_flag_.set_inclusive_end(); scan_param.set_version_range(version_range); for (int64_t i = 0; i < COL_NUM; ++i) { scan_param.add_column(cell_infos[0][i].column_id_); } int64_t count = 0; const int64_t timeout = 10 * 1000L; int err = client.ups_scan(scan_param, scanner, timeout); fprintf(stderr, "ups_scan err=%d\n", err); // check result count = 0; ObScannerIterator iter; for (iter = scanner.begin(); iter != scanner.end(); iter++) { ObCellInfo ci; ObCellInfo expected = cell_infos[count / COL_NUM][count % COL_NUM]; EXPECT_EQ(OB_SUCCESS, iter.get_cell(ci)); check_cell(expected, ci); ++count; } EXPECT_EQ(ROW_NUM * COL_NUM, count); fprintf(stderr, "cell_num=%ld\n", count); client.destroy(); return 0; }
TEST_F(TestGet, test_get_one_row) { int err = 0; CommonSchemaManagerWrapper schema_mgr; tbsys::CConfig config; bool ret_val = schema_mgr.parse_from_file("scan_schema.ini", config); ASSERT_TRUE(ret_val); ObUpsTableMgr& mgr = ObUpdateServerMain::get_instance()->get_update_server().get_table_mgr(); err = mgr.init(); ASSERT_EQ(0, err); err = mgr.set_schemas(schema_mgr); ASSERT_EQ(0, err); TestUpsTableMgrHelper test_helper(mgr); TableMgr& table_mgr = test_helper.get_table_mgr(); table_mgr.sstable_scan_finished(10); TableItem* active_memtable_item = table_mgr.get_active_memtable(); MemTable& active_memtable = active_memtable_item->get_memtable(); // construct multi-row mutator static const int64_t ROW_NUM = 1; static const int64_t COL_NUM = 10; ObCellInfo cell_infos[ROW_NUM][COL_NUM]; char row_key_strs[ROW_NUM][50]; uint64_t table_id = 10; // init cell infos for (int64_t i = 0; i < ROW_NUM; ++i) { sprintf(row_key_strs[i], "row_key_%08ld", i); for (int64_t j = 0; j < COL_NUM; ++j) { cell_infos[i][j].table_id_ = table_id; cell_infos[i][j].row_key_.assign(row_key_strs[i], strlen(row_key_strs[i])); cell_infos[i][j].column_id_ = j + 1; cell_infos[i][j].value_.set_int(1000 + i * COL_NUM + j); } } ObUpsMutator ups_mutator; ObMutator &mutator = ups_mutator.get_mutator(); // add cell to array for (int64_t i = 0; i < ROW_NUM; ++i) { for (int64_t j = 0; j < COL_NUM; ++j) { ObMutatorCellInfo mutator_cell; mutator_cell.cell_info = cell_infos[i][j]; mutator_cell.op_type.set_ext(ObActionFlag::OP_UPDATE); err = mutator.add_cell(mutator_cell); EXPECT_EQ(0, err); } } // write row to active memtable MemTableTransHandle write_handle; err = active_memtable.start_transaction(WRITE_TRANSACTION, write_handle); ASSERT_EQ(0, err); ups_mutator.set_mutate_timestamp(0); err = active_memtable.set(write_handle, ups_mutator); EXPECT_EQ(0, err); err = active_memtable.end_transaction(write_handle); ASSERT_EQ(0, err); /* ObString text; text.assign("/tmp", strlen("/tmp")); active_memtable.dump2text(text); */ for (int64_t i = 0; i < ROW_NUM; ++i) { ObScanner scanner; ObGetParam get_param; //get_param.set_timestamp(version); ObVersionRange version_range; //version_range.start_version_ = version; //version_range.end_version_ = version; version_range.start_version_ = 2; version_range.end_version_ = 2; version_range.border_flag_.set_inclusive_start(); version_range.border_flag_.set_inclusive_end(); get_param.set_version_range(version_range); for (int64_t j = 0; j < COL_NUM; ++j) { get_param.add_cell(cell_infos[i][j]); } int64_t count = 0; err = mgr.get(get_param, scanner, tbsys::CTimeUtil::getTime(), 2000000000 * 1000L * 1000L); EXPECT_EQ(0, err); // check result count = 0; while (OB_SUCCESS == scanner.next_cell()) { ObCellInfo* p_cell = NULL; scanner.get_cell(&p_cell); ASSERT_TRUE(p_cell != NULL); ObCellInfo expected = cell_infos[count / COL_NUM + i][count % COL_NUM]; check_cell(expected, *p_cell); ++count; } EXPECT_EQ(COL_NUM, count); } }
void conway_test() { force_write(1,2,is_world_calc); force_write(2,2,is_world_calc); force_write(3,2,is_world_calc); display_world(); //write_cell(3, 3, 2); //display_world(); printf("%i \n",check_cell(1, 2, is_world_calc)); printf("%i \n",check_cell(2, 2, is_world_calc)); printf("%i \n",check_cell(3, 2, is_world_calc)); printf("%i \n",check_cell(2, 1, is_world_calc)); on_tick(); printf("%i \n",check_cell(1, 2, is_world_calc)); printf("%i \n",check_cell(2, 2, is_world_calc)); printf("%i \n",check_cell(3, 2, is_world_calc)); printf("%i \n",check_cell(2, 1, is_world_calc)); on_tick(); printf("%i \n",check_cell(1, 2, is_world_calc)); printf("%i \n",check_cell(2, 2, is_world_calc)); printf("%i \n",check_cell(3, 2, is_world_calc)); printf("%i \n",check_cell(2, 1, is_world_calc)); on_tick(); }
TEST_F(TestUpsMutator, test_api_mutator) { int err = OB_SUCCESS; ObUpsMutator ups_mutator; ObCellInfo cell_info; ObString table_name; table_name.assign((char*)"oceanbase_table", static_cast<int32_t>(strlen("oceanbase_table"))); ObRowkey row_key; row_key = make_rowkey("row_key", &allocator_); ObString column_name; column_name.assign((char*)"column_name", static_cast<int32_t>(strlen("column_name"))); int64_t table_id = 10; uint64_t column_id = 5; int64_t value = 100; // init cell infos cell_info.table_name_ = table_name; cell_info.row_key_ = row_key; cell_info.column_name_ = column_name; cell_info.value_.set_int(value); ObMutator mutator; ObMutatorCellInfo mutation; mutation.cell_info = cell_info; mutation.op_type.set_ext(ObActionFlag::OP_UPDATE); err = mutator.add_cell(mutation); EXPECT_EQ(0, err); char buf[1024]; int64_t pos = 0; err = mutator.serialize(buf, sizeof(buf), pos); EXPECT_EQ(0, err); pos = 0; err = ups_mutator.get_mutator().deserialize(buf, sizeof(buf), pos); EXPECT_EQ(0, err); ObMutatorCellInfo* new_cell_info = NULL; err = ups_mutator.next_cell(); EXPECT_EQ(0, err); err = ups_mutator.get_cell(&new_cell_info); EXPECT_EQ(0, err); EXPECT_TRUE(NULL != new_cell_info); check_cell_with_name(cell_info, new_cell_info->cell_info); err = ups_mutator.next_cell(); EXPECT_EQ(OB_ITER_END, err); new_cell_info->cell_info.column_id_ = column_id; new_cell_info->cell_info.table_id_ = table_id; new_cell_info->cell_info.column_name_.assign(NULL, 0); new_cell_info->cell_info.table_name_.assign(NULL, 0); cell_info.table_id_ = table_id; cell_info.column_id_ = column_id; ups_mutator.reset_iter(); err = ups_mutator.next_cell(); EXPECT_EQ(0, err); err = ups_mutator.get_cell(&new_cell_info); EXPECT_EQ(0, err); EXPECT_TRUE(NULL != new_cell_info); check_cell(cell_info, new_cell_info->cell_info); err = ups_mutator.next_cell(); EXPECT_EQ(OB_ITER_END, err); }