void drvSAMPL::show_rectangle(const float llx, const float lly, const float urx, const float ury) { outf << "Rectangle ( " << llx << "," << lly << ") (" << urx << "," << ury << ") equivalent to:" << endl; // just do show_path for a first guess show_path(); }
int main(void) { #define N_NODES 6 node_t *nodes = (node_t*)calloc(sizeof(node_t), N_NODES); for (int i = 0; i < N_NODES; i++) sprintf(nodes[i].name, "%c", 'a' + i); add_edge(nodes, nodes+1, 7); //a-b add_edge(nodes, nodes+2, 9); //a-c add_edge(nodes, nodes+5, 14); //a-f add_edge(nodes+1, nodes+2, 10); //b-c add_edge(nodes+1, nodes+3, 15); //b-d add_edge(nodes+2, nodes+3, 11); //c-d add_edge(nodes+2, nodes+5, 2); //c-f add_edge(nodes+3, nodes+4, 6); //d-e add_edge(nodes+4, nodes+5, 9); //e-f heap = (node_t**)calloc(sizeof(node_t), N_NODES + 1); heap_len = 0; calc_all(nodes); for (int i = 0; i < N_NODES; i++) { show_path(nodes + i); putchar('\n'); } //free memories free_edges(); free(heap); free(nodes); return 0; }
void drvCAIRO::show_rectangle(const float llx, const float lly, const float urx, const float ury) { // FIXME -- I need to get some rectangle calls into my sample so i can test this... // cairo_rectangle (cr, x, y, width, height); outf << " cairo_rectangle (cr, " << llx << "," << lly << ", " << urx-llx << "," << ury-lly << ");" << endl; // just do show_path for a first guess show_path(); }
void show_paths(vector<Path>& p){ cout<<"[ "; for(int i=0;i<p.size();i++){ show_path(p[i]); cout<<" "; } cout<<"]"; }
void show_path(node_t *const nd) { if (nd->via == nd) printf("%s", nd->name); else if (!nd->via) printf("%s(unreached)", nd->name); else { show_path(nd->via); printf("-> %s(%g) ", nd->name, nd->dist); } }
int show_path(node_t *start_node, node_t *destination_node) { if (destination_node->via == destination_node) return destination_node->name; else if (!destination_node->via) return 999; else { if (destination_node->via == start_node) { return destination_node->name; } else { return show_path(start_node, destination_node->via); } } }
int regedit_getch(void) { int c; SMB_ASSERT(regedit_main); c = getch(); if (c == KEY_RESIZE) { tree_view_resize(regedit_main->keys, KEY_HEIGHT, KEY_WIDTH, KEY_START_Y, KEY_START_X); value_list_resize(regedit_main->vl, VAL_HEIGHT, VAL_WIDTH, VAL_START_Y, VAL_START_X); print_heading(regedit_main); show_path(regedit_main); } return c; }
int dijkstra(const int num_nodes, int ** nodes_cost, int ** routing_table) { int i; # define N_NODES num_nodes // For each node for (int start = 0; start < N_NODES; start++) { // create the nodes node_t *nodes = calloc(sizeof(node_t), N_NODES); // give the node name (ID) for (i = 0; i < N_NODES; i++) { nodes[i].name = i; } # define E(a, b, c) add_edge(nodes + a, nodes + b, c) // load the data from the cost table to the memory for (int i = 0; i < N_NODES; i++) { for (int j = 0; j < N_NODES; j++) { if (nodes_cost[i][j] != 0) { E(i, j, nodes_cost[i][j]); } } } # undef E // Create HEAP heap = calloc(sizeof(heap_t), N_NODES + 1); heap_len = 0; // Calculate all path fro current node to al other nodes calc_all(nodes + start); for (i = 0; i < N_NODES; i++) { routing_table[(nodes + start)->name][(nodes + i)->name] = show_path(nodes + start, nodes + i); } // Free memory free_edges(); free(heap); free(nodes); } return 0; }
int main(int argc, char **argv) { int pass; (void)argc; (void)argv; /* defaults to blank */ al_set_org_name("liballeg.org"); /* defaults to the exename, set it here to remove the .exe on windows */ al_set_app_name("ex_get_path"); if (!al_init()) { abort_example("Could not init Allegro.\n"); } open_log(); for (pass = 1; pass <= 3; pass++) { if (pass == 1) { log_printf("With default exe name:\n"); } else if (pass == 2) { log_printf("\nOverriding exe name to blahblah\n"); al_set_exe_name("blahblah"); } else if (pass == 3) { log_printf("\nOverriding exe name to /tmp/blahblah.exe:\n"); al_set_exe_name("/tmp/blahblah.exe"); } show_path(ALLEGRO_RESOURCES_PATH, "RESOURCES_PATH"); show_path(ALLEGRO_TEMP_PATH, "TEMP_PATH"); show_path(ALLEGRO_USER_DATA_PATH, "USER_DATA_PATH"); show_path(ALLEGRO_USER_SETTINGS_PATH, "USER_SETTINGS_PATH"); show_path(ALLEGRO_USER_HOME_PATH, "USER_HOME_PATH"); show_path(ALLEGRO_USER_DOCUMENTS_PATH, "USER_DOCUMENTS_PATH"); show_path(ALLEGRO_EXENAME_PATH, "EXENAME_PATH"); } close_log(true); return 0; }
int main(void) { TGraph graph; int path[NUM_VEX]; int dist[NUM_VEX]; int i, k; for(i =0 ; i < NUM_VEX; i++){ graph.vex[NUM_VEX] = i; } for(i =0 ; i < NUM_VEX; i++){ for(k = 0; k < NUM_VEX; k++){ graph.arc[i][k] = MAX; } graph.arc[i][i] = 0; } graph.arc[0][2] = 10; graph.arc[0][4] = 30; graph.arc[0][5] = 100; graph.arc[1][2] = 5; graph.arc[2][3] = 50; graph.arc[3][5] = 10; graph.arc[4][3] = 20; graph.arc[4][5] = 60; //// 测试输出 //for(i =0 ; i < NUM_VEX; i++){ // for(k = 0; k < NUM_VEX; k++){ // printf("%5d", graph.arc[i][k]); // } // printf("\n"); //} Dijkstra(graph, 0, path, dist); show_path(path, dist); system("pause"); return 0; }
int main(int argc, char *argv[]) { unsigned int T, N, t, a, b, l; scanf("%u%u", &T, &N); node_t *nodes = calloc(sizeof(node_t), N); for (t = 0; t < T; ++t) { scanf("%u%u%u", &a, &b, &l); --a; --b; add_edge(nodes + a, nodes + b, l); add_edge(nodes + b, nodes + a, l); } heap = calloc(sizeof(heap_t), N); heap_len = 0; calc_all(nodes); for (i = 0; i < N; i++) { show_path(nodes + i); putchar('\n'); } free_edges(); free(heap); free(nodes); return 0; }
void drvVTK::show_rectangle(const float llx, const float lly, const float urx, const float ury) { // just do show_path for a first guess show_path(); }
int collisionfinding(parameters_type& parameters) { bool usetunnelbitconditions = parameters.usetunnelbitconditions; sha1messagespace tmpspace; vector< vector<uint32> > bitrels, tmpbitrel, tmpbitrel2; for (unsigned i = 0; i < parameters.rnd234_m_bitrelationfiles.size(); ++i) { try { cout << "Loading '" << parameters.rnd234_m_bitrelationfiles[i] << "'..." << flush; load_bz2(tmpspace, text_archive, parameters.rnd234_m_bitrelationfiles[i]); cout << "done" << flush; tmpspace.tobitrelations_80(tmpbitrel); bitrels.insert(bitrels.end(), tmpbitrel.begin(), tmpbitrel.end()); cout << " (" << tmpbitrel.size() << " bitrels, new total: " << bitrels.size() << ")" << endl; } catch (std::exception& e) { cerr << "Exception:" << endl << e.what() << endl; return 1; } } vector< sha1differentialpath > paths; cout << "Loading round 1 paths from '" << parameters.rnd1_pathsfile << "'..." << flush; try { load_bz2(paths, text_archive, parameters.rnd1_pathsfile); cout << "done (" << paths.size() << " paths)." << endl; } catch (std::exception& e) { cerr << "Exception:" << endl << e.what() << endl; return 1; } if (paths.size() == 0) exit(0); vector< vector<uint32> > bitrelsbu = bitrels; for (unsigned pi = 0; pi < paths.size(); ++pi) { try { bitrels = bitrelsbu; sha1differentialpath upperpath; cout << "Loading round 2,3,4 path from '" << parameters.rnd234_pathfile << "'..." << flush; try { load_bz2(upperpath, text_archive, parameters.rnd234_pathfile); cout << "done." << endl; } catch (std::exception& e) { cerr << "Exception:" << endl << e.what() << endl; return 1; } for (int t = paths[pi].tbegin(); t < paths[pi].tend(); ++t) upperpath[t] = paths[pi][t]; for (unsigned t = 0; t < paths[pi].tend()-1; ++t) upperpath.getme(t) = paths[pi].getme(t); cleanup_path(upperpath); maindiffpath = upperpath; bool bad = false; for (int t = maindiffpath.tbegin()+4; t < maindiffpath.tend()-1; ++t) { if (maindiffpath.getme(t).mask != parameters.m_mask[t]) { uint32 dm = maindiffpath.getme(t).adddiff(); uint32 mcur = 0; uint32 mmask = parameters.m_mask[t]; uint32 madd = (~mmask)+1; sdr msdr; msdr.mask = mmask; do { mcur += madd; mcur &= mmask; msdr.sign = mcur; if (msdr.adddiff() == dm) { cout << "corrected: \t" << t << ":\t" << msdr << " == " << sdr(parameters.m_mask[t]) << endl; break; } } while (mcur != 0); if (msdr.adddiff() == dm) { maindiffpath.getme(t) = msdr; } else { bad = true; cout << "failed: \t" << t << ":\t" << maindiffpath.getme(t) << " != " << sdr(parameters.m_mask[t]) << endl; } } } if (bad) exit(0); show_path(maindiffpath); // remove bitrelations possibly limiting me[0],...,me[19] const unsigned tend_fix_me = parameters.tend_rnd1_me; cout << "Fixed me diffs for t=[0," << tend_fix_me << "): (" << bitrels.size() << "=>" << flush; filter_bitconditions(bitrels, tend_fix_me, 80); cout << bitrels.size() << ")" << endl; for (unsigned i = 0; i < bitrels.size(); ++i) { cout << " - "; bool firstone = true; for (unsigned t = 0; t < 80; ++t) for (unsigned b = 0; b < 32; ++b) if (bitrels[i][t] & (1<<b)) { if (firstone) firstone = false; else cout << " + "; cout << "M[" << t << "," << b << "]"; } cout << " = " << (bitrels[i][80]&1) << endl; } tmpspace.clear(); for (unsigned t = 0; t < 80; ++t) { if (t < tend_fix_me) { for (unsigned b = 0; b < 31; ++b) { int bit = maindiffpath.getme(t).get(b); if (bit == 0) tmpspace.buildbasis_addfreebit(t,b); else tmpspace.buildbasis_setbit(t,b,bit==-1); } tmpspace.buildbasis_addfreebit(t,31); } else { for (unsigned b = 0; b < 32; ++b) tmpspace.buildbasis_addfreebit(t,b); } } tmpspace.tobitrelations_80(tmpbitrel); bitrels.insert(bitrels.end(), tmpbitrel.begin(), tmpbitrel.end()); cout << "Extra me [0," << tend_fix_me << ") bitrelations: " << tmpbitrel.size() << endl; { cout << "Extra tunnel me bitrelations: " << endl; ifstream ifs("tunnel_bitconditions.txt"); read_message_bitconditions(ifs, tmpbitrel); for (unsigned i = 0; i < tmpbitrel.size(); ++i) { bool firstone = true; for (unsigned t = 0; t < 80; ++t) if (tmpbitrel[i][t]) { if (firstone) firstone = false; else cout << "+ "; cout << "m" << t << sdr(tmpbitrel[i][t]) << " "; } cout << "= " << (tmpbitrel[i][80]&1) << endl; } bitrels.insert(bitrels.end(), tmpbitrel.begin(), tmpbitrel.end()); } tmpspace.frombitrelations_80(bitrels); mainmespace = tmpspace; tmpspace.tobitrelations_16(bitrels); cout << "Total bitrelations: " << bitrels.size() << endl; #if 0 cout << "Independent message bits: " << endl; uint32 meindep[16]; for (unsigned i = 0; i < 16; ++i) meindep[16] = ~uint32(0); for (unsigned i = 0; i < bitrels.size(); ++i) for (unsigned t = 0; t < 16; ++t) meindep[t] &= ~bitrels[i][t]; for (unsigned i = 0; i < 16; ++i) { cout << "m[" << i << "] indep:\t"; for (int b = 31; b >= 0; --b) cout << ((meindep[i]&(1<<b))?"1":"0"); cout << endl; } #endif pathbitrelations = bitrels; pathbitrelationsmatrix.clear(); pathbitrelationsmatrix.resize(16); for (unsigned i = 0; i < 16; ++i) pathbitrelationsmatrix[i].resize(32); for (unsigned i = 0; i < pathbitrelations.size(); ++i) { int lastcol = -1; for (int col = 16*32-1; col >= 0; --col) if (pathbitrelations[i][col>>5]&(1<<(col&31))) { lastcol = col; unsigned t = lastcol>>5; unsigned b = lastcol&31; pathbitrelationsmatrix[t][b] = pathbitrelations[i]; break; } if (lastcol == -1) throw; } #if 0 //needs diffpath & pathbitrelationsmatrix analyze_indepsection_prob(); #endif if (parameters.tunnelfile.size()) { vector<sha1differentialpath> tunnels; cout << "Loading tunnels from '" << parameters.tunnelfile << "'..." << flush; try { load_bz2(tunnels, text_archive, parameters.tunnelfile); } catch (std::exception &e) { tunnels.clear(); cout << "failed:" << endl << e.what() << endl; } catch (...) { tunnels.clear(); cout << "failed." << endl; } if (tunnels.size()) analyze_tunnels_diffpath(maindiffpath, bitrels, tunnels); exit(0); } if (!usetunnelbitconditions) { // if not using tunnel bit conditions then we'll assume we want to analyze tunnels analyze_tunnels_diffpath(maindiffpath, bitrels); exit(0); } // if we're using tunnel bit conditions we'll assume we want to generate the collision finding program generate_program(); break; } catch (std::exception& e) { cerr << "c: " << e.what() << endl; } catch (...) {} } // for (unsigned pi = 0; pi < paths.size(); ++pi) }
static void print_path(struct regedit *regedit, struct tree_node *node) { regedit->path_len = tree_node_print_path(regedit->path_label, node); show_path(regedit); }
static void display_window(TALLOC_CTX *mem_ctx, struct registry_context *ctx) { struct regedit *regedit; struct tree_node *root; bool colors; int key; initscr(); cbreak(); noecho(); colors = has_colors(); if (colors) { start_color(); use_default_colors(); } regedit = talloc_zero(mem_ctx, struct regedit); SMB_ASSERT(regedit != NULL); regedit_main = regedit; regedit->main_window = stdscr; keypad(regedit->main_window, TRUE); mvwprintw(regedit->main_window, 0, 0, "Path: "); regedit->path_label = newpad(1, PATH_WIDTH_MAX); SMB_ASSERT(regedit->path_label); wprintw(regedit->path_label, "/"); show_path(regedit_main); root = load_hives(regedit, ctx); SMB_ASSERT(root != NULL); regedit->keys = tree_view_new(regedit, root, KEY_HEIGHT, KEY_WIDTH, KEY_START_Y, KEY_START_X); SMB_ASSERT(regedit->keys != NULL); regedit->vl = value_list_new(regedit, VAL_HEIGHT, VAL_WIDTH, VAL_START_Y, VAL_START_X); SMB_ASSERT(regedit->vl != NULL); regedit->tree_input = true; print_heading(regedit); tree_view_show(regedit->keys); menu_driver(regedit->keys->menu, REQ_FIRST_ITEM); load_values(regedit); value_list_show(regedit->vl); update_panels(); doupdate(); do { key = regedit_getch(); handle_main_input(regedit, key); update_panels(); doupdate(); } while (key != 'q' || key == 'Q'); endwin(); }