int main() { init_state_descriptors(); set_descriptors(triples); print_descriptors(); build_tables(); print_tables(); check_tables(); return 0; }
LowestCommonAncestor( int root, const AdjacencyList<EdgeType> &graph) : m_depth_table(graph.size(), -1) , m_skip_table( graph.size(), std::vector<int>(32 - __builtin_clz(graph.size()), -1)) { std::vector<int> s; build_tables(root, s, graph); }
void build_tables( int u, std::vector<int> &s, const AdjacencyList<EdgeType> &graph) { if(m_depth_table[u] >= 0){ return; } const int d = s.size(), m = m_skip_table.size(); for(int i = 0, j = 1; i < m && j <= d; ++i, j += j){ m_skip_table[u][i] = s[d - j]; } m_depth_table[u] = d; s.push_back(u); for(size_t i = 0; i < graph[u].size(); ++i){ build_tables(graph[u][i].to, s, graph); } s.pop_back(); }
/** * @brief Create/connect to the SQLite database. * @param(in) dbpath The database file to create. * @return The sqlite3 connection data structure if successful, NULL otherwise. */ sqlite3 *db_connect(const char *dbpath) { int sql_errno = SQLITE_OK; sqlite3 *dbconn = NULL; char *the_dbpath = NULL; if (dbpath) { the_dbpath = xstrdup(dbpath); } else { the_dbpath = get_default_db_path(); } if ((sql_errno = sqlite3_open(the_dbpath, &dbconn)) != SQLITE_OK) { fprintf(stderr, "Failed to open a connection to the database file '%s' (%s).\n", the_dbpath, mtracks_sqlite_strerror(sql_errno)); if (dbconn && (sql_errno = sqlite3_close(dbconn)) != SQLITE_OK) { fprintf(stderr, "Failed to tidy up SQL connection resource (%s).\n", mtracks_sqlite_strerror(sql_errno)); } dbconn = NULL; goto out; } if (build_tables(dbconn) != 0) { fprintf(stderr, "Failed to create database tables.\n"); if ((sql_errno = sqlite3_close(dbconn)) != SQLITE_OK) { fprintf(stderr, "Failed to tidy up SQL connection resource (%s).\n", mtracks_sqlite_strerror(sql_errno)); } dbconn = NULL; goto out; } out: free(the_dbpath); the_dbpath = NULL; return (dbconn); }
main(int argc,char *argv[]) { int codesize; char *z; printf("%d\n",sizeof(TKOUZLO)); if (argc<2) { puts("Tento program vyzaduje jmeno souboru, ve kterem se nalezaji\n" "platne definice kouzel pro hru BRANY SKELDALU v 1.0"); exit(0); } puts(""); puts("Prob¡h kompilace:"); puts(" Spouçt¡m program LEX_LIB.EXE\n"); // putenv("DOS4G=QUIET"); z=(char *)malloc(strlen(argv[1])+10); sprintf(z,"\"%s\"",argv[1]); if (_spawnlp(P_WAIT,GetLexLibPath(),"lex_lib.exe",z,"temp.$$$",NULL)) exit(1); free(z); if (errno) { puts("Nemohu spustit program lex_lib.exe"); exit(1); } puts("Byla kompilov na tato kouzla:"); puts("¬¡slo, zaŸ tek, jmeno:"); puts("======================"); memset(kouzla_tab,0,sizeof(kouzla_tab)); init("temp.$$$"); codesize=build_tables(); add_prog_command(0xff); fclose(source); save_tab("kouzla.dat"); remove("temp.$$$"); puts("Kompilace £spØçn ..."); printf("D‚lka k¢du: %d (+%d)",codesize,sizeof(kouzla_tab)); }
int main(int argc, char** argv) { /* * argv[1] = first run's directory * argv[2] = second run's directory */ if (argc != 4) { DEBUG(stderr, "argv[1] = first run's directory, argv[2] = second run's directory, argv[3] = input file\n"); } assert(argc == 4); DEBUG(stderr, "argv0 = %s, argv1 = %s, argv2 = %s \n", argv[0], argv[1], argv[2]); first_dir = (struct directory_files*) malloc(sizeof(struct directory_files)); second_dir = (struct directory_files*) malloc(sizeof(struct directory_files)); gettimeofday(&stats.start, NULL); DEBUG(stderr, "init_filename\n"); if (!init_filenames(argv[1], argv[2], argv[3])) { fprintf(stderr, "init filenames failed\n"); exit(1); } DEBUG(stderr, "build_address_lookup\n"); if (!build_address_lookup(first_dir->snapshot, second_dir->snapshot)) { fprintf(stderr, "build_dictionary failed\n"); exit(1); } build_tables(first_dir, second_dir); // init_get_input_addrs(second_dir->dataflow_result); process_outputs(argv[3]); save_outputs(); gettimeofday(&stats.end, NULL); print_stats(stats); return 1; }
static int get_system_info( papi_mdi_t *mdi ) { int retval; pid_t pid; char maxargs[PAPI_MAX_STR_LEN] = "<none>"; psinfo_t psi; int fd; int hz, version; char cpuname[PAPI_MAX_STR_LEN], pname[PAPI_HUGE_STR_LEN]; /* Check counter access */ if ( cpc_version( CPC_VER_CURRENT ) != CPC_VER_CURRENT ) return ( PAPI_ESBSTR ); SUBDBG( "CPC version %d successfully opened\n", CPC_VER_CURRENT ); if ( cpc_access( ) == -1 ) return ( PAPI_ESBSTR ); /* Global variable cpuver */ cpuver = cpc_getcpuver( ); SUBDBG( "Got %d from cpc_getcpuver()\n", cpuver ); if ( cpuver == -1 ) return ( PAPI_ESBSTR ); #ifdef DEBUG { if ( ISLEVEL( DEBUG_SUBSTRATE ) ) { const char *name; int i; name = cpc_getcpuref( cpuver ); if ( name ) SUBDBG( "CPC CPU reference: %s\n", name ); else SUBDBG( "Could not get a CPC CPU reference\n" ); for ( i = 0; i < cpc_getnpic( cpuver ); i++ ) { SUBDBG( "\n%6s %-40s %8s\n", "Reg", "Symbolic name", "Code" ); cpc_walk_names( cpuver, i, "%6d %-40s %02x\n", print_walk_names ); } SUBDBG( "\n" ); } } #endif /* Initialize other globals */ if ( ( retval = build_tables( ) ) != PAPI_OK ) return retval; preset_search_map = preset_table; if ( cpuver <= CPC_ULTRA2 ) { SUBDBG( "cpuver (==%d) <= CPC_ULTRA2 (==%d)\n", cpuver, CPC_ULTRA2 ); pcr_shift[0] = CPC_ULTRA_PCR_PIC0_SHIFT; pcr_shift[1] = CPC_ULTRA_PCR_PIC1_SHIFT; } else if ( cpuver <= LASTULTRA3 ) { SUBDBG( "cpuver (==%d) <= CPC_ULTRA3x (==%d)\n", cpuver, LASTULTRA3 ); pcr_shift[0] = CPC_ULTRA_PCR_PIC0_SHIFT; pcr_shift[1] = CPC_ULTRA_PCR_PIC1_SHIFT; _solaris_vector.cmp_info.hardware_intr = 1; _solaris_vector.cmp_info.hardware_intr_sig = SIGEMT; } else return ( PAPI_ESBSTR ); /* Path and args */ pid = getpid( ); if ( pid == -1 ) return ( PAPI_ESYS ); /* Turn on microstate accounting for this process and any LWPs. */ sprintf( maxargs, "/proc/%d/ctl", ( int ) pid ); if ( ( fd = open( maxargs, O_WRONLY ) ) == -1 ) return ( PAPI_ESYS ); { int retval; struct { long cmd; long flags; } cmd; cmd.cmd = PCSET; cmd.flags = PR_MSACCT | PR_MSFORK; retval = write( fd, &cmd, sizeof ( cmd ) ); close( fd ); SUBDBG( "Write PCSET returned %d\n", retval ); if ( retval != sizeof ( cmd ) ) return ( PAPI_ESYS ); } /* Get executable info */ sprintf( maxargs, "/proc/%d/psinfo", ( int ) pid ); if ( ( fd = open( maxargs, O_RDONLY ) ) == -1 ) return ( PAPI_ESYS ); read( fd, &psi, sizeof ( psi ) ); close( fd ); /* Cut off any arguments to exe */ { char *tmp; tmp = strchr( psi.pr_psargs, ' ' ); if ( tmp != NULL ) *tmp = '\0'; } if ( realpath( psi.pr_psargs, pname ) ) strncpy( _papi_hwi_system_info.exe_info.fullname, pname, PAPI_HUGE_STR_LEN ); else strncpy( _papi_hwi_system_info.exe_info.fullname, psi.pr_psargs, PAPI_HUGE_STR_LEN ); /* please don't use pr_fname here, because it can only store less that 16 characters */ strcpy( _papi_hwi_system_info.exe_info.address_info.name, basename( _papi_hwi_system_info.exe_info.fullname ) ); SUBDBG( "Full Executable is %s\n", _papi_hwi_system_info.exe_info.fullname ); /* Executable regions, reading /proc/pid/maps file */ retval = _ultra_hwd_update_shlib_info( &_papi_hwi_system_info ); /* Hardware info */ _papi_hwi_system_info.hw_info.ncpu = sysconf( _SC_NPROCESSORS_ONLN ); _papi_hwi_system_info.hw_info.nnodes = 1; _papi_hwi_system_info.hw_info.totalcpus = sysconf( _SC_NPROCESSORS_CONF ); retval = scan_prtconf( cpuname, PAPI_MAX_STR_LEN, &hz, &version ); if ( retval == -1 ) return ( PAPI_ESBSTR ); strcpy( _papi_hwi_system_info.hw_info.model_string, cpc_getcciname( cpuver ) ); _papi_hwi_system_info.hw_info.model = cpuver; strcpy( _papi_hwi_system_info.hw_info.vendor_string, "SUN" ); _papi_hwi_system_info.hw_info.vendor = PAPI_VENDOR_SUN; _papi_hwi_system_info.hw_info.revision = version; _papi_hwi_system_info.hw_info.mhz = ( ( float ) hz / 1.0e6 ); SUBDBG( "hw_info.mhz = %f\n", _papi_hwi_system_info.hw_info.mhz ); /* Number of PMCs */ retval = cpc_getnpic( cpuver ); if ( retval < 0 ) return ( PAPI_ESBSTR ); _solaris_vector.cmp_info.num_cntrs = retval; _solaris_vector.cmp_info.fast_real_timer = 1; _solaris_vector.cmp_info.fast_virtual_timer = 1; _solaris_vector.cmp_info.default_domain = PAPI_DOM_USER; _solaris_vector.cmp_info.available_domains = PAPI_DOM_USER | PAPI_DOM_KERNEL; /* Setup presets */ retval = _papi_hwi_setup_all_presets( preset_search_map, NULL ); if ( retval ) return ( retval ); return ( PAPI_OK ); }