void SolveCube2::make_table_prun_template(int n1,int n2, int table1[][9], int table2[][9],char *table_deep,char*table_pre_move) { /* if(load_table("cube2_depth.dat",table_deep,n1*n2)) { int max_depth=0; for(int i=0;i<n1*n2;i++) { if(table_deep[i]>max_depth) { max_depth=table_deep[i]; } } std::cout<<"cube 2 max depth:"<<max_depth<<std::endl; if(load_table("cube2_pre_move.dat",table_pre_move,n1*n2)) { return; } } */ if(load_table("cube2_pre_move.dat",table_pre_move,n1*n2)) { return; } std::deque<int> temp; //temp.reserve(n1*n2); int count; int x,x1,x2; int y,y1,y2; int deep; memset(table_deep,-1,n1*n2); table_deep[0]=0; table_pre_move[0]=-1; count=1; temp.push_back(0); while(temp.empty()==false) { x=temp.front(); temp.pop_front(); x1= x/n2; x2= x%n2; deep= table_deep[x]; for(int i=0;i<9;i++) { y1=table1[x1][i]; y2=table2[x2][i]; y=y1*n2+y2; if(table_deep[y]==-1) { temp.push_back(y); table_deep[y]=deep+1; table_pre_move[y]=i; count++; } } } assert(count==n1*n2); //save_table("cube2_depth.dat",table_deep,n1*n2); save_table("cube2_pre_move.dat",table_pre_move,n1*n2); }
int db__driver_close_database() { int i; for (i = 0; i < db.ntables; i++) { save_table(i); free_table(i); } G_free(db.tables); return DB_OK; }
/* Returns LUAAMF_ESUCCESS on success, error code on failure */ static int save_value( luaamf_SaveBuffer * sb, lua_State * L, int index, int use_code ) { int result = LUAAMF_EFAILURE; switch (lua_type(L, index)) { case LUA_TNIL: sb_writechar(sb, LUAAMF_NULL); result = LUAAMF_ESUCCESS; break; case LUA_TBOOLEAN: sb_writechar(sb, lua_toboolean(L, index) ? LUAAMF_TRUE : LUAAMF_FALSE); result = LUAAMF_ESUCCESS; break; case LUA_TNUMBER: result = encode_double(sb, lua_tonumber(L, index)); break; case LUA_TSTRING: { size_t len; const char * buf = lua_tolstring(L, index, &len); if(use_code) { sb_writechar(sb, LUAAMF_STRING); } result = encode_string(sb, buf, len); break; } case LUA_TTABLE: result = save_table(L, sb, index); break; case LUA_TNONE: case LUA_TFUNCTION: case LUA_TTHREAD: case LUA_TUSERDATA: default: result = LUAAMF_EBADTYPE; } return result; }
int main(int argc, char **argv){ int N = atoi(argv[1]); printf("Generating an %d x %d table\n", N, N); int *table = (int *)calloc(N,N*sizeof(int)); generate_table(table, N); save_table(table, N); free(table); }
/* Returns 0 on success, non-zero on failure */ static int save_value( lua_State * L, luabins_SaveBuffer * sb, int index, int nesting ) { int result = LUABINS_ESUCCESS; switch (lua_type(L, index)) { case LUA_TNIL: result = lbs_writeNil(sb); break; case LUA_TBOOLEAN: result = lbs_writeBoolean(sb, lua_toboolean(L, index)); break; case LUA_TNUMBER: result = lbs_writeNumber(sb, lua_tonumber(L, index)); break; case LUA_TSTRING: { size_t len = 0; const char * buf = lua_tolstring(L, index, &len); result = lbs_writeString(sb, buf, len); } break; case LUA_TTABLE: result = save_table(L, sb, index, nesting + 1); break; case LUA_TNONE: case LUA_TFUNCTION: case LUA_TTHREAD: case LUA_TUSERDATA: default: result = LUABINS_EBADTYPE; } return result; }
void reduce_tables(void) { int i; ubyte v[256]; if (!copybuf) copybuf = malloc(COPYSIZE); collect_stats(0); if (generate_dtz) { save_table(table_w, 'w'); if (!symmetric) save_table(table_b, 'b'); } for (i = 0; i < 256; i++) v[i] = 0; #ifndef SUICIDE v[BROKEN] = BROKEN; v[UNKNOWN] = UNKNOWN; v[CHANGED] = CHANGED; v[CAPT_DRAW] = CAPT_DRAW; v[MATE] = MATE; v[ILLEGAL] = ILLEGAL; v[CAPT_WIN] = CAPT_WIN; if (num_saves == 0) { for (i = 0; i < DRAW_RULE; i++) { v[WIN_IN_ONE + i] = WIN_IN_ONE; v[LOSS_IN_ONE - i] = MATE; } v[CAPT_CWIN] = CAPT_CWIN_RED; for (; i < REDUCE_PLY - 2; i++) { v[WIN_IN_ONE + i + 1] = CAPT_CWIN_RED + 1; v[LOSS_IN_ONE - i] = LOSS_IN_ONE; } v[LOSS_IN_ONE - i] = LOSS_IN_ONE; v[WIN_IN_ONE + REDUCE_PLY - 1] = CAPT_CWIN_RED + 2; v[WIN_IN_ONE + REDUCE_PLY] = CAPT_CWIN_RED + 3; v[WIN_IN_ONE + REDUCE_PLY + 1] = CAPT_CWIN_RED + 4; v[LOSS_IN_ONE - REDUCE_PLY + 1] = LOSS_IN_ONE - 1; } else { v[WIN_IN_ONE] = WIN_IN_ONE; v[LOSS_IN_ONE] = LOSS_IN_ONE; v[CAPT_CWIN_RED] = CAPT_CWIN_RED; v[CAPT_CWIN_RED + 1] = CAPT_CWIN_RED + 1; for (i = 0; i < REDUCE_PLY_RED; i++) { v[CAPT_CWIN_RED + i + 2] = CAPT_CWIN_RED + 1; v[LOSS_IN_ONE - i - 1] = LOSS_IN_ONE; } v[CAPT_CWIN_RED + REDUCE_PLY_RED + 2] = CAPT_CWIN_RED + 2; v[CAPT_CWIN_RED + REDUCE_PLY_RED + 3] = CAPT_CWIN_RED + 3; v[CAPT_CWIN_RED + REDUCE_PLY_RED + 4] = CAPT_CWIN_RED + 4; v[LOSS_IN_ONE - REDUCE_PLY_RED - 1] = LOSS_IN_ONE - 1; } #else v[BROKEN] = BROKEN; v[UNKNOWN] = UNKNOWN; v[CHANGED] = CHANGED; v[CAPT_WIN] = CAPT_WIN; v[CAPT_CWIN] = CAPT_CWIN; v[CAPT_DRAW] = CAPT_DRAW; v[CAPT_CLOSS] = CAPT_CLOSS; v[CAPT_LOSS] = CAPT_LOSS; v[THREAT_WIN] = THREAT_WIN; if (num_saves == 0) { for (i = 3; i <= DRAW_RULE; i++) v[BASE_WIN + i] = BASE_WIN + 3; v[THREAT_CWIN1] = BASE_WIN + 4; v[THREAT_CWIN2] = BASE_WIN + 4; v[BASE_WIN + DRAW_RULE + 1] = BASE_WIN + 5; for (i = DRAW_RULE + 2; i < REDUCE_PLY; i++) v[BASE_WIN + i + 2] = BASE_WIN + 5; for (i = 2; i <= DRAW_RULE; i++) v[BASE_LOSS - i] = BASE_LOSS - 2; for (; i < REDUCE_PLY; i++) v[BASE_LOSS - i] = BASE_LOSS - 3; v[BASE_WIN + REDUCE_PLY + 2] = BASE_WIN + 6; v[BASE_WIN + REDUCE_PLY + 3] = BASE_WIN + 7; v[BASE_LOSS - REDUCE_PLY] = BASE_LOSS - 4; } else { v[BASE_WIN + 3] = BASE_WIN + 3; v[BASE_WIN + 4] = BASE_WIN + 4; v[BASE_WIN + 5] = BASE_WIN + 5; v[BASE_LOSS - 2] = BASE_LOSS - 2; v[BASE_LOSS - 3] = BASE_LOSS - 3; for (i = 0; i < REDUCE_PLY_RED; i++) { v[BASE_WIN + i + 6] = BASE_WIN + 5; v[BASE_LOSS - i - 4] = BASE_LOSS - 3; } v[BASE_WIN + REDUCE_PLY_RED + 6] = BASE_WIN + 6; v[BASE_WIN + REDUCE_PLY_RED + 7] = BASE_WIN + 7; v[BASE_LOSS - REDUCE_PLY_RED - 4] = BASE_LOSS - 4; } #endif transform_v = v; run_threaded(transform, work_g, 1); if (num_saves == 0) reduce_cnt = REDUCE_PLY - DRAW_RULE - 2; else reduce_cnt += REDUCE_PLY_RED; }
void add_cell(const std::string& cell_name, const std::string& table_name, const std::string& row_name, const std::string& type_name) { // // Load the table, add our data, and re-write: // std::string table_id = "table_" + sanitize_string(table_name); std::string column_heading = BOOST_COMPILER; column_heading += "[br]"; column_heading += BOOST_PLATFORM; column_heading += "[br]"; column_heading += type_name; boost::regex table_e("\\[table:" + table_id + "\\s[^\\[]+" "((\\[" "([^\\[\\]]*(?2)?)*" "\\]\\s*)*\\s*)" "\\]" ); boost::smatch table_location; if(regex_search(content, table_location, table_e)) { std::vector<std::vector<std::string> > table_data; load_table(table_data, table_location[1].first, table_location[1].second); // // Figure out which column we're on: // unsigned column_id = 1001u; for(unsigned i = 0; i < table_data[0].size(); ++i) { if(table_data[0][i] == column_heading) { column_id = i; break; } } if(column_id > 1000) { // // Need a new column, must be adding a new compiler to the table! // table_data[0].push_back(column_heading); for(unsigned i = 1; i < table_data.size(); ++i) table_data[i].push_back(std::string()); column_id = table_data[0].size() - 1; } // // Figure out the row: // unsigned row_id = 1001; for(unsigned i = 1; i < table_data.size(); ++i) { if(table_data[i][0] == row_name) { row_id = i; break; } } if(row_id > 1000) { // // Need a new row, add it now: // table_data.push_back(std::vector<std::string>()); table_data.back().push_back(row_name); for(unsigned i = 1; i < table_data[0].size(); ++i) table_data.back().push_back(std::string()); row_id = table_data.size() - 1; } // // Update the entry: // std::string& s = table_data[row_id][column_id]; if(s.empty()) { std::cout << "Adding " << cell_name << " to empty cell."; s = "[" + cell_name + "]"; } else { if(cell_name.find("_boost_") != std::string::npos) { std::cout << "Adding " << cell_name << " to start of cell."; s.insert(0, "[" + cell_name + "][br][br]"); } else { std::cout << "Adding " << cell_name << " to end of cell."; if((s.find("_boost_") != std::string::npos) && (s.find("[br]") == std::string::npos)) s += "[br]"; // extra break if we're adding directly after the boost results. s += "[br][" + cell_name + "]"; } } // // Convert back to a string and insert into content: std::string c = save_table(table_data); content.replace(table_location.position(1), table_location.length(1), c); } else { // // Create a new table and try again: // std::string new_table = "\n[template " + table_id; new_table += "[]\n[table:" + table_id; new_table += " Error rates for "; new_table += table_name; new_table += "\n[[]["; new_table += column_heading; new_table += "]]\n"; new_table += "[["; new_table += row_name; new_table += "][["; new_table += cell_name; new_table += "]]]\n]\n]\n"; std::string::size_type pos = content.find("[/tables:]"); if(pos != std::string::npos) content.insert(pos + 10, new_table); else content += "\n\n[/tables:]\n" + new_table; // // Add a section for this table as well: // std::string section_id = "section_" + sanitize_string(table_name); if(content.find(section_id + "[]") == std::string::npos) { std::string new_section = "\n[template " + section_id + "[]\n[section:" + section_id + " " + table_name + "]\n[" + table_id + "]\n[endsect]\n]\n"; pos = content.find("[/sections:]"); if(pos != std::string::npos) content.insert(pos + 12, new_section); else content += "\n\n[/sections:]\n" + new_section; add_to_all_sections(section_id); } // // Add to list of all tables (not in sections): // add_to_all_sections(table_id, "all_tables"); } }
void add_cell(boost::intmax_t val, const std::string& table_name, const std::string& row_name, const std::string& column_heading) { // // Load the table, add our data, and re-write: // std::string table_id = "table_" + sanitize_string(table_name); boost::regex table_e("\\[table:" + table_id + "\\s[^\\[]++" "((\\[" "([^\\[\\]]*+(?2)?+)*+" "\\]\\s*+)*+\\s*+)" "\\]" ); boost::smatch table_location; if(regex_search(content, table_location, table_e)) { std::vector<std::vector<std::string> > table_data; load_table(table_data, table_location[1].first, table_location[1].second); // // Figure out which column we're on: // unsigned column_id = 1001u; for(unsigned i = 0; i < table_data[0].size(); ++i) { if(table_data[0][i] == column_heading) { column_id = i; break; } } if(column_id > 1000) { // // Need a new column, must be adding a new compiler to the table! // table_data[0].push_back(column_heading); for(unsigned i = 1; i < table_data.size(); ++i) table_data[i].push_back(std::string()); column_id = table_data[0].size() - 1; } // // Figure out the row: // unsigned row_id = 1001; for(unsigned i = 1; i < table_data.size(); ++i) { if(table_data[i][0] == row_name) { row_id = i; break; } } if(row_id > 1000) { // // Need a new row, add it now: // table_data.push_back(std::vector<std::string>()); table_data.back().push_back(row_name); for(unsigned i = 1; i < table_data[0].size(); ++i) table_data.back().push_back(std::string()); row_id = table_data.size() - 1; } // // Find the best result in this row: // boost::uintmax_t best = (std::numeric_limits<boost::uintmax_t>::max)(); std::vector<boost::intmax_t> values; for(unsigned i = 1; i < table_data[row_id].size(); ++i) { if(i == column_id) { if(val < best) best = val; values.push_back(val); } else { std::cout << "Existing cell value was " << table_data[row_id][i] << std::endl; boost::uintmax_t cell_val = get_value_from_cell(table_data[row_id][i]); std::cout << "Extracted value: " << cell_val << std::endl; if(cell_val < best) best = cell_val; values.push_back(cell_val); } } // // Update the row: // for(unsigned i = 1; i < table_data[row_id].size(); ++i) { std::string& s = table_data[row_id][i]; s = "[role "; if(values[i - 1] < 0) { s += "grey -]"; } else { s += get_colour(values[i - 1], best); s += " "; s += format_precision(static_cast<double>(values[i - 1]) / best, 2); s += "[br]("; s += boost::lexical_cast<std::string>(values[i - 1]) + "ns)]"; } } // // Convert back to a string and insert into content: std::sort(table_data.begin() + 1, table_data.end(), [](std::vector<std::string> const& a, std::vector<std::string> const& b) { return a[0] < b[0]; } ); std::string c = save_table(table_data); content.replace(table_location.position(1), table_location.length(1), c); } else { // // Create a new table and try again: // std::string new_table = "\n[template " + table_id; new_table += "[]\n[table:" + table_id; new_table += " "; new_table += table_name; new_table += "\n[[Function]["; new_table += column_heading; new_table += "]]\n"; new_table += "[["; new_table += row_name; new_table += "][[role blue 1.00[br]("; new_table += boost::lexical_cast<std::string>(val); new_table += "ns)]]]\n]\n]\n"; std::string::size_type pos = content.find("[/tables:]"); if(pos != std::string::npos) content.insert(pos + 10, new_table); else content += "\n\n[/tables:]\n" + new_table; // // Add a section for this table as well: // std::string section_id = "section_" + sanitize_string(table_name); if(content.find(section_id + "[]") == std::string::npos) { std::string new_section = "\n[template " + section_id + "[]\n[section:" + section_id + " " + table_name + "]\n[" + table_id + "]\n[endsect]\n]\n"; pos = content.find("[/sections:]"); if(pos != std::string::npos) content.insert(pos + 12, new_section); else content += "\n\n[/sections:]\n" + new_section; add_to_all_sections(section_id); } // // Add to list of all tables (not in sections): // add_to_all_sections(table_id, "performance_all_tables"); } }
void reduce_tables(int local) { int i; ubyte v[256]; long64 *work; long64 save_begin = begin; if (!copybuf) copybuf = malloc(COPYSIZE); if (local == num_saves) { work = work_part; fill_work(total_work, begin + (1ULL << shift[numpawns - 1]), 0, work); begin = 0; reduce_val[local] = ply; work = work_part; } else work = work_p; collect_stats(work, 0, local); if (generate_dtz) { save_table(table_w, 'w', local, begin, work[total_work]); if (!symmetric) save_table(table_b, 'b', local, begin, work[total_work]); } for (i = 0; i < 256; i++) v[i] = 0; #ifndef SUICIDE v[BROKEN] = BROKEN; v[UNKNOWN] = UNKNOWN; v[CHANGED] = CHANGED; v[CAPT_DRAW] = CAPT_DRAW; v[PAWN_DRAW] = PAWN_DRAW; v[MATE] = MATE; v[ILLEGAL] = ILLEGAL; v[CAPT_WIN] = CAPT_WIN; if (local == 0) { v[PAWN_WIN] = WIN_RED; for (i = 0; i < DRAW_RULE; i++) { v[WIN_IN_ONE + i] = WIN_RED; v[LOSS_IN_ONE - i] = MATE; } v[CAPT_CWIN] = CAPT_CWIN_RED; v[PAWN_CWIN] = CAPT_CWIN_RED + 1; for (; i < REDUCE_PLY - 2; i++) { v[WIN_IN_ONE + i + 2] = CAPT_CWIN_RED + 1; v[LOSS_IN_ONE - i] = LOSS_IN_ONE; } v[LOSS_IN_ONE - i] = LOSS_IN_ONE; v[WIN_IN_ONE + REDUCE_PLY] = CAPT_CWIN_RED + 2; v[WIN_IN_ONE + REDUCE_PLY + 1] = CAPT_CWIN_RED + 3; v[WIN_IN_ONE + REDUCE_PLY + 2] = CAPT_CWIN_RED + 4; v[LOSS_IN_ONE - REDUCE_PLY + 1] = LOSS_IN_ONE - 1; } else { v[WIN_RED] = WIN_RED; v[LOSS_IN_ONE] = LOSS_IN_ONE; v[CAPT_CWIN_RED] = CAPT_CWIN_RED; v[CAPT_CWIN_RED + 1] = CAPT_CWIN_RED + 1; for (i = 0; i < REDUCE_PLY_RED; i++) { v[CAPT_CWIN_RED + i + 2] = CAPT_CWIN_RED + 1; v[LOSS_IN_ONE - i - 1] = LOSS_IN_ONE; } v[CAPT_CWIN_RED + REDUCE_PLY_RED + 2] = CAPT_CWIN_RED + 2; v[CAPT_CWIN_RED + REDUCE_PLY_RED + 3] = CAPT_CWIN_RED + 3; v[CAPT_CWIN_RED + REDUCE_PLY_RED + 4] = CAPT_CWIN_RED + 4; v[LOSS_IN_ONE - REDUCE_PLY_RED - 1] = LOSS_IN_ONE - 1; } #else v[BROKEN] = BROKEN; v[UNKNOWN] = UNKNOWN; v[CHANGED] = CHANGED; v[CAPT_WIN] = CAPT_WIN; v[CAPT_CWIN] = CAPT_CWIN; v[CAPT_DRAW] = CAPT_DRAW; v[CAPT_CLOSS] = CAPT_CLOSS; v[CAPT_LOSS] = CAPT_LOSS; v[PAWN_DRAW] = PAWN_DRAW; if (local == 0) { v[THREAT_WIN1] = THREAT_WIN_RED; v[THREAT_WIN2] = THREAT_WIN_RED; v[STALE_WIN] = BASE_WIN_RED; v[STALE_WIN + 1] = BASE_WIN_RED; for (i = 2; i <= DRAW_RULE; i++) v[BASE_WIN + i] = BASE_WIN_RED; v[THREAT_CWIN1] = THREAT_CWIN_RED; v[THREAT_CWIN2] = THREAT_CWIN_RED; v[BASE_WIN + DRAW_RULE + 1] = BASE_CWIN_RED; for (i = DRAW_RULE + 2; i < REDUCE_PLY; i++) v[BASE_WIN + i + 2] = BASE_CWIN_RED; for (i = 0; i <= DRAW_RULE; i++) v[BASE_LOSS - i] = BASE_LOSS_RED; for (; i < REDUCE_PLY; i++) v[BASE_LOSS - i] = BASE_CLOSS_RED; v[BASE_WIN + REDUCE_PLY + 2] = BASE_CWIN_RED + 1; v[BASE_WIN + REDUCE_PLY + 3] = BASE_CWIN_RED + 2; v[BASE_LOSS - REDUCE_PLY] = BASE_CLOSS_RED - 1; } else { v[THREAT_WIN_RED] = THREAT_WIN_RED; v[BASE_WIN_RED] = BASE_WIN_RED; v[THREAT_CWIN_RED] = THREAT_CWIN_RED; v[BASE_CWIN_RED] = BASE_CWIN_RED; v[BASE_LOSS_RED] = BASE_LOSS_RED; v[BASE_CLOSS_RED] = BASE_CLOSS_RED; for (i = 0; i < REDUCE_PLY_RED; i++) { v[BASE_CWIN_RED + i + 1] = BASE_CWIN_RED; v[BASE_CLOSS_RED - i - 1] = BASE_CLOSS_RED; } v[BASE_CWIN_RED + REDUCE_PLY_RED + 1] = BASE_CWIN_RED + 1; v[BASE_CWIN_RED + REDUCE_PLY_RED + 2] = BASE_CWIN_RED + 2; v[BASE_CLOSS_RED - REDUCE_PLY_RED - 1] = BASE_CLOSS_RED - 1; } #endif transform_v = v; run_threaded(transform, work, 0); if (local == num_saves) { if (num_saves == 0) reduce_cnt[0] = ply - DRAW_RULE - 2; else reduce_cnt[num_saves] = reduce_cnt[num_saves - 1] + ply; begin = save_begin; num_saves++; } }
PinyinEngine::~PinyinEngine() { save_table(); }
/* handle the save command */ int saver() { char buf[FILENAME_LENGTH]; strcpy(buf, config_file); if (file_select_ex("Save Keyboard Config", buf, "CFG", sizeof(buf), 0, 0)) { if ((stricmp(config_file, buf) != 0) && (exists(buf))) { if (alert("Overwrite existing file?", NULL, NULL, "Yes", "Cancel", 'y', 27) != 1) return D_REDRAW; } strlwr(buf); strcpy(config_file, buf); push_config_state(); set_config_file(buf); set_config_string(NULL, "keyboard_name", keyboard_name); set_config_int("key_escape", "accent1", _key_accent1); set_config_int("key_escape", "accent2", _key_accent2); set_config_int("key_escape", "accent3", _key_accent3); set_config_int("key_escape", "accent4", _key_accent4); set_config_int("key_escape", "accent1_flag", _key_accent1_flag); set_config_int("key_escape", "accent2_flag", _key_accent2_flag); set_config_int("key_escape", "accent3_flag", _key_accent3_flag); set_config_int("key_escape", "accent4_flag", _key_accent4_flag); save_table(_key_ascii_table, orig_key_ascii_table, "key_ascii"); save_table(_key_capslock_table, orig_key_capslock_table, "key_capslock"); save_table(_key_shift_table, orig_key_shift_table, "key_shift"); save_table(_key_control_table, orig_key_control_table, "key_control"); if (split_altgr) { save_table(_key_altgr_lower_table, orig_key_altgr_lower_table, "key_altgr_lower"); save_table(_key_altgr_upper_table, orig_key_altgr_upper_table, "key_altgr_upper"); } else { save_table(_key_altgr_lower_table, orig_key_altgr_lower_table, "key_altgr"); } save_table(_key_accent1_lower_table, orig_key_accent1_lower_table, "key_accent1_lower"); save_table(_key_accent1_upper_table, orig_key_accent1_upper_table, "key_accent1_upper"); save_table(_key_accent2_lower_table, orig_key_accent2_lower_table, "key_accent2_lower"); save_table(_key_accent2_upper_table, orig_key_accent2_upper_table, "key_accent2_upper"); save_table(_key_accent3_lower_table, orig_key_accent3_lower_table, "key_accent3_lower"); save_table(_key_accent3_upper_table, orig_key_accent3_upper_table, "key_accent3_upper"); save_table(_key_accent4_lower_table, orig_key_accent4_lower_table, "key_accent4_lower"); save_table(_key_accent4_upper_table, orig_key_accent4_upper_table, "key_accent4_upper"); pop_config_state(); } return D_REDRAW; }