// dynamically expand hash table void expand_table(hash_table *h) { int i, index, new_size; new_size = next_prime(h->capacity * 2 + 1); // create new, expanded hash table hash_table *new_table = create_table(new_size); printf("Hash table before expansion to size %d:\n", new_size); print_table(h); // rehash elements from the old table into the new table for (i = 0; i < h->capacity; i++) { if (h->table[i] != NULL) { index = get_pos(new_table, *h->table[i]); new_table->table[index] = h->table[i]; new_table->size++; } } free(h->table); h->table = new_table->table; h->size = new_table->size; h->capacity = new_table->capacity; free(new_table); printf("Hash table after expansion:\n"); print_table(h); }
void print_state(state_t *state) { print_table(state->table1); if (state->table2) { print_table(state->table2); print_edge(state); } }
int main(int argc, char* argv[]) { HashTable *ht; char *val; ht = hash_init_table(); hash_put(ht, "apple", "red"); hash_put(ht, "lemon", "yellow"); hash_put(ht, "orange", "orange"); print_table(ht); hash_put(ht, "orange", "green"); print_table(ht); hash_delete(ht, "orange"); print_table(ht); val = hash_get(ht, "apple"); val = hash_get(ht, "lemon"); val = hash_get(ht, "orange"); hash_uninit_table(ht); return 0; }
static void __attribute__ ((__noreturn__)) usage(int exitcode) { FILE *out = exitcode == EXIT_SUCCESS ? stdout : stderr; fputs(USAGE_HEADER, out); fprintf(out, _(" %s [options] <ldisc> <device>\n"), program_invocation_short_name); fputs(USAGE_OPTIONS, out); fputs(_(" -d, --debug print verbose messages to stderr\n"), out); fputs(_(" -s, --speed <value> set serial line speed\n"), out); fputs(_(" -7, --sevenbits set character size to 7 bits\n"), out); fputs(_(" -8, --eightbits set character size to 8 bits\n"), out); fputs(_(" -n, --noparity set parity to none\n"), out); fputs(_(" -e, --evenparity set parity to even\n"), out); fputs(_(" -o, --oddparity set parity to odd\n"), out); fputs(_(" -1, --onestopbit set stop bits to one\n"), out); fputs(_(" -2, --twostopbits set stop bits to two\n"), out); fputs(_(" -i, --iflag [-]<iflag> set input mode flag\n"), out); fputs(USAGE_SEPARATOR, out); fputs(USAGE_HELP, out); fputs(USAGE_VERSION, out); fputs(_("\nKnown <ldisc> names:\n"), out); print_table(out, ld_discs); fputs(_("\nKnown <iflag> names:\n"), out); print_table(out, ld_iflags); fputc('\n', out); fprintf(out, USAGE_MAN_TAIL("ldattach(8)")); exit(exitcode); }
int main() { struct Table* tbl = create_table(); insert(tbl,"value0",0); insert(tbl,"value1",1); insert(tbl,"value2",2); print_table(tbl); printf("Removing value1\n"); { int val = erase(tbl,"value1"); printf("value1 had value %d\n",val); } print_table(tbl); { int val = find(tbl,"value2"); printf("value2 has value %d\n",val); val = find(tbl,"valuex"); if (val == -99999) printf("can't find valuex\n"); val = erase(tbl,"valuex"); if (val == -99999) printf("can't erase valuex\n"); } destroy(tbl); }
int main() { int loop = 1; int input = -1; while(loop) { printf("Virtual memory to Main memory mapping:\n"); printf("--------------------------------------\n"); printf("1) Set parameters\n"); printf("2) Map virtual address\n"); printf("3) Print page table\n"); printf("4) Quit\n"); printf("\n"); printf("Enter selection: "); scanf("%d", &input); switch(input) { case 1: setparameters(); break; case 2: map_addr(); break; case 3: print_table(); break; case 4: loop = 0; break; default: printf("Invalid selection."); } printf("\n\n"); } return 0; }
void RestaurantPrinter::print_restaurants_that_accept(string payment_type) { Table restaurants = database_->query("placeID", "PaymentType", "payment = '" + payment_type + "'"); Table results = lookup_and_combine_restaurant_tables(restaurants, 0); print_table("Restaurants With Payment Type: " + payment_type, results); }
void RestaurantPrinter::print_restaurants_with_cuisine(string cuisine) { Table restaurants = database_->query("placeID", "Cuisine", "cuisine = '" + cuisine + "'"); Table results = lookup_and_combine_restaurant_tables(restaurants, 0); print_table("Restaurants With Cuisine: " + cuisine, results); }
static PLI_INT32 regfileCheckCallTf() { s_vpi_value value; static int counter = 0; // countes the clock cycles int passed = 0; update_time(); value.format = vpiIntVal; for (int i = 0; i < ARGS_NR; ++i) { vpi_get_value(args[i].handle, &value); args[i].value = value.value.integer; } // compare w_data with r_data if (args[4].value == args[5].value && args[4].value == args[6].value && args[0].value != 0) passed = 1; else if (args[0].value != 0) passed = -1; else passed = 0; print_table(args, ARGS_NR, &g_time, &counter, &passed); ++counter; return 0; }
void RestaurantPrinter::print_restaurants_with_at_least_average_rating(float minimum_rating) { Table restaurants = database_->query("*", "Locations", ""); // create a table with the same structure as Ratings Table restaurants_with_min_average(database_->query("*", "Ratings", "").attributes()); for_each_record(restaurants, [&] (Record &record) { Table ratings = database_->query("*", "Ratings", "placeID = '" + record.retrieve(0) + "'"); float average = ratings.sum("rating") / ratings.count("rating"); // if it meets the minimum we want to insert the FIRST instance of the rating // into the table so that the placeID is present once, and can be passed to // lookup_and_combine_restaurant_tables() if (average > minimum_rating) { TableIterator it(ratings); it.first(); Record record = it.getRecord(); vector<string> attributes; for (int i = 0; i < record.size(); i++) { attributes.push_back(record.retrieve(i)); } restaurants_with_min_average.insert(attributes); } }); print_table("Restaurants With Minimum Average Rating", lookup_and_combine_restaurant_tables(restaurants_with_min_average, 1)); }
int main() { CassFuture* connect_future = NULL; CassCluster* cluster = cass_cluster_new(); CassSession* session = cass_session_new(); cass_cluster_set_contact_points(cluster, "127.0.0.1"); connect_future = cass_session_connect(session, cluster); if (cass_future_error_code(connect_future) == CASS_OK) { CassFuture* close_future = NULL; execute_query(session, "CREATE KEYSPACE examples WITH replication = { \ 'class': 'SimpleStrategy', 'replication_factor': '3' };"); print_keyspace(session, "examples"); execute_query(session, "CREATE TABLE examples.schema_meta (key text, \ value bigint, \ PRIMARY KEY (key));"); print_table(session, "examples", "schema_meta"); /* Close the session */ close_future = cass_session_close(session); cass_future_wait(close_future); cass_future_free(close_future); } else {
void CashboxWindow::delete_selected_table_row() { int rowNum; QString hotkeyName; QList<QTableWidgetItem*> row = this->product_table->selectedItems(); if(row.count()==4) { for(int i = 0; i < row.count();i++) { //Only delete rows.. if(i == 0) { rowNum = row.at(i)->row(); hotkeyName = row.at(1)->text(); } if(rowNum == row.at(i)->row()) { row.at(i)->~QTableWidgetItem(); } if(i == 3) { this->totalPrice -= row.at(i)->text().toDouble(); this->lbTotalPrice->setText(QString::number(this->totalPrice)+"€"); } } } //Set Hotkey-Count = 0 for(int i = 0; i < MyHotkeys.count(); i++) { //Set count 0 if(MyHotkeys.at(i)->getProductname()==hotkeyName) { MyHotkeys.at(i)->setCount(0); } } print_table(); }
int main(void){ int i,j; char tc; int find; while(1){ for(i=0;i<8;i++){//读棋盘 scanf("%s",ch[i]); if(ch[i][0]=='-'){ return 0; } } find=0; for(i=0;i<8;i++){//找起点 for(j=0;j<8;j++){ tc=ch[i][j]; if(tc=='<'||tc=='>'||tc=='^'||tc=='v'){ r=i; c=j; find=1; if(tc=='^'){ direction=0; break; } if(tc=='>'){ direction=1; break; } if(tc=='v'){ direction=2; break; } if(tc=='<'){ direction=3; break; } } } if(find){ break; } } while(1){//读scripts scanf("%s",command); if(command[0]=='#'){ break; } if(command[0]=='m'){ scanf("%d",&step); moveOn(); }else{ scanf("%s",dc); turn(); } } print_table(); } return 0; }
// Print all elements of a stack void print_stack(struct stack *top){ while(top){ print_table(top->table); printf("%d\n",top->step); top=top->next; } }
int main() { int n, i, v; char verb[4], prep[4]; block *blocks[MAX]; block *a, *b; for(i = 0; i < MAX; i++) table[i] = blocks[i] = NULL; /* Read number of blocks `n`. */ Si(n); /* Initialize world with `n` blocks. */ for(i = 0; i < n; i++) { table[i] = blocks[i] = (block *) malloc(sizeof(block)); blocks[i]->above = NULL; blocks[i]->below = NULL; blocks[i]->table_loc = i; blocks[i]->value = i; } while(1) { /* Read the verb. */ Ss(verb); /* Exit when verb is quit. */ if(verb[0] == 'q') break; /* Read the object. */ Si(v); a = blocks[v]; /* Read the preposition. */ Ss(prep); /* Read the complement. */ Si(v); b = blocks[v]; /* Ignore action if it is illegal. */ if(a->table_loc == b->table_loc) continue; /* When verb is `move`, put back that are above the object `a`. */ if(verb[0] == 'm') put_back(a); /* When preposition is `onto`, put back the blocks that are above the complement `b`. */ if(prep[1] == 'n') put_back(b); /* Pile object `a` over complement `b`. */ stack(a, b); } print_table(n); for(i = 0; i < n; i++) free(blocks[i]); return 0; }
int main (void) { char s[21], /* a temp word variable */ table[200][21]; /* the table of words */ int ns[200]; /* array of occurences */ int n; /* count variable */ for(n=0;n<199;n++) ns[n]=1; /* set up the array */ n=0; do { get_word(s); /* input a word from the inout */ if (!strcmp(s,"* no more *")) { /* If it is the end of the file : */ print_table(sort(table,ns,n),n,ns); return(0); } convert_word(s); /* make the word loower case */ if (!lookup(s,table,n,ns)) { /* word is not in the table yet */ insert_word(s,table,n); n++; } } while (1); /* wont quit until the end of file is reached */ }
void rip_incoming(ssize_t n) /* Use a RIP packet to add to the router table. (RIP packets are really for * between routers, but often it is the only information around.) */ { udp_io_hdr_t *udp_io_hdr; u32_t default_dist; i32_t pref; routeinfo_t *routeinfo; struct routedata *data, *end; /* We don't care about RIP packets when there are router adverts. */ if (now + MaxAdvertisementInterval < router_advert_valid) return; udp_io_hdr= (udp_io_hdr_t *) rip_buf; if (udp_io_hdr->uih_data_len != n - sizeof(*udp_io_hdr)) { if (debug) printf("Bad sized route packet (discarded)\n"); return; } routeinfo= (routeinfo_t *) (rip_buf + sizeof(*udp_io_hdr) + udp_io_hdr->uih_ip_opt_len); if (routeinfo->command != RIP_REPLY) { if (debug) { printf("RIP-%d packet command %d ignored\n", routeinfo->version, routeinfo->command); } return; } /* Look for a default route, the route to the gateway. */ end= (struct routedata *) (rip_buf + n); default_dist= (u32_t) -1; for (data= routeinfo->data; data < end; data++) { if (ntohs(data->family) != AF_INET || data->ip_addr != 0) continue; default_dist= ntohl(data->metric); if (default_dist >= 256) { if (debug) { printf("Strange metric %lu\n", (unsigned long) default_dist); } } } pref= default_dist >= 256 ? 1 : 512 - default_dist; pref+= priority_offset; /* Add the gateway to the table with the calculated preference. */ add_gateway(udp_io_hdr->uih_src_addr, pref); if (debug) { printf("Routing table after RIP-%d packet from %s:\n", routeinfo->version, addr2name(udp_io_hdr->uih_src_addr)); print_table(); } /* Start advertizing. */ if (next_advert == NEVER) next_advert= IMMEDIATELY; }
int main(int argv, char **argc) { FILE *input_file; char *filename = argc[1]; struct dev_set_c *set_info; struct table **table_array; /* table_bdev[bdev_nr]*/ error_t error_msg; if ( !(input_file = fopen(filename, "r")) ) { printf("No such file %s\n", filename); return -1; } get_devs_info(argv, argc, &set_info); alloc_table_array(set_info, &table_array); init_table(set_info, table_array); if ( map(input_file, set_info, table_array) < 0) { printf("[ERROR] : can not do mapping workload to your device\n"); return -1; } print_devs_info(set_info); print_table(set_info, table_array); //ratio = find_scale_ratio(set_info, &last_blk_info); //printf("%lf %u %llu %u %x\n", one_req_info.time, one_req_info.devno, one_req_info.blkno, one_req_info.bcount, one_req_info.is_read); return 0; }
void user_interface( ){ // window dimensions int maxX, maxY, cursor = 0; // iterate until its time to exit while( true ){ // get the window size maxX = getmaxx(stdscr); maxY = getmaxy(stdscr); // clear the screen clear(); // print the header print_header("Task Listing", maxX); // print the table print_table( maxX, maxY, 4 , cursor); // print the footer print_footer( GUI, maxX, maxY ); // get the input int arg = getch(); // exit the program if( arg == 27 ) break; // create a new task else if( arg == 'c' || arg == 'C' ){ create_task( ); } // view the selected task else if( arg == 'V' || arg == 'v' ){ view_task( ); } // move the cursor up else if( arg == KEY_UP ){ cursor--; if( cursor < 0 ){ cursor = options.tasks.size()-1; } } // move the cursor down else if( arg == KEY_DOWN ){ cursor++; if( cursor >= options.tasks.size() ) cursor = 0; } } }
int main() { printf("table.c tests\n"); printf("table_dimensions = %d, %d\n", table_dims.x, table_dims.y); init_table(); printf("table_dimensions = %d, %d\n", table_dims.x, table_dims.y); print_table(); printf("expand_table_cols()\n"); expand_table_cols(); printf("table_dimensions = %d, %d\n", table_dims.x, table_dims.y); print_table(); printf("expand_table_rows()\n"); expand_table_rows(); printf("table_dimensions = %d, %d\n", table_dims.x, table_dims.y); print_table(); }
/* * parse_args Parse the arguments from the command line into the fields * structure. Inputs: argc, argv Output: the table of name/value pairs for the * object being created is filled in with values from the arg list. Returns 0 * Success 1 if error For every name/value pair in the arg list, search for * the name in the field_table (all possible argument names) and fill the * value in the table. Note: An error message is printed for every argument * that is not in the fields table. All arguments are parsed. */ int parse_args( int argc, char **argv, int index, struct object_field *tbl) { int i, n, err = 0; char *cur, *name, *value; int name_len; memset(parse_errstr, 0, sizeof(parse_errstr)); // for every argument in the list, update the table with the new value // first arg is program name and second is object type. The remainder are // object fields for (i = index; i < argc; i++) { cur = argv[i]; name = cur; value = strchr(cur, '='); if (value == NULL) { if (err != 0) // not first error, add comma strcat(parse_errstr, ", "); strcat(parse_errstr, cur); err = 1; } else { // find the right place in the table to put // the value name_len = value - name; if ((n = fieldInTable(name, name_len, tbl)) >= 0) tbl[n].value = stripws(++value); else { if (err != 0) // not first error, add comma strcat(parse_errstr, ", "); strcat(parse_errstr, name); err = 1; } } } // done #ifdef DEBUG if (err == 0) print_table(tbl); #endif return err; }
Table_ Table(string id, int value, struct table *tail) { Table_ t = malloc(sizeof(*t)); t->id = id; t->value = value; t->tail = tail; print_table(t); return t; }
int game( void ) { init_table(); print_table(); return 0; }
void advertize(ipaddr_t host) /* Send a router advert to a host. */ { char *buf, *data; ip_hdr_t *ip_hdr; icmp_hdr_t *icmp_hdr; int i; table_t *ptab; buf= malloc(sizeof(*ip_hdr) + offsetof(icmp_hdr_t, ih_dun.uhd_data) + table_size * (sizeof(ipaddr_t) + sizeof(u32_t))); if (buf == nil) fatal("heap error"); ip_hdr= (ip_hdr_t *) buf; icmp_hdr= (icmp_hdr_t *) (ip_hdr + 1); ip_hdr->ih_vers_ihl= 0x45; ip_hdr->ih_dst= host; icmp_hdr->ih_type= ICMP_TYPE_ROUTER_ADVER; icmp_hdr->ih_code= 0; icmp_hdr->ih_hun.ihh_ram.iram_na= 0; icmp_hdr->ih_hun.ihh_ram.iram_aes= 2; icmp_hdr->ih_hun.ihh_ram.iram_lt= htons(AdvertisementLifetime); data= (char *) icmp_hdr->ih_dun.uhd_data; /* Collect gateway entries from the table. */ for (i= 0, ptab= table; i < table_size; i++, ptab++) { if (ptab->tab_time < now - DEAD_TO) continue; icmp_hdr->ih_hun.ihh_ram.iram_na++; if (ptab->tab_time < now - DEST_TO) ptab->tab_pref= DEAD_PREF; * (ipaddr_t *) data= ptab->tab_gw; data+= sizeof(ipaddr_t); * (i32_t *) data= htonl(ptab->tab_pref); data+= sizeof(i32_t); } icmp_hdr->ih_chksum= 0; icmp_hdr->ih_chksum= ~oneC_sum(0, icmp_hdr, data - (char *) icmp_hdr); if (icmp_hdr->ih_hun.ihh_ram.iram_na > 0) { /* Send routing info. */ if (debug) { printf("Routing table send to %s:\n", addr2name(host)); print_table(); } if (write(irdp_fd, buf, data - buf) < 0) { (errno == EIO ? fatal : report)(ip_device); } } free(buf); }
void get_db_stats(struct database *db) { /* Deal with paths later - problem is, they will be biased by length of folder_base at the moment. */ int size = 4096; int *len_counts, *enc_len_counts, *enc_counts; int max_len, max_enc_len, max_enc; max_len = 0; max_enc_len = 0; max_enc = 0; len_counts = new_array(int, size); memset(len_counts, 0, size * sizeof(int)); enc_len_counts = new_array(int, size); memset(enc_len_counts, 0, size * sizeof(int)); enc_counts = new_array(int, size); memset(enc_counts, 0, size * sizeof(int)); do_toktable(db->to, len_counts, enc_len_counts, enc_counts, size, &max_len, &max_enc_len, &max_enc); do_toktable(db->cc, len_counts, enc_len_counts, enc_counts, size, &max_len, &max_enc_len, &max_enc); do_toktable(db->from, len_counts, enc_len_counts, enc_counts, size, &max_len, &max_enc_len, &max_enc); do_toktable(db->subject, len_counts, enc_len_counts, enc_counts, size, &max_len, &max_enc_len, &max_enc); do_toktable(db->body, len_counts, enc_len_counts, enc_counts, size, &max_len, &max_enc_len, &max_enc); #if 0 /* no longer works now that the msg_ids table has 2 encoding chains. fix * this when required. */ do_toktable(db->msg_ids, len_counts, enc_len_counts, enc_counts, size, &max_len, &max_enc_len, &max_enc); #endif printf("Max token length : %d\n", max_len); print_table(len_counts, max_len); printf("Max encoding vector length : %d\n", max_enc_len); print_table(enc_len_counts, max_enc_len); printf("Max encoding increment : %d\n", max_enc); print_table(enc_counts, max_enc); return; }
int insert_ytable(int y[][N],int row,int col,int key) { if(y[row-1][col-1] < INF) { fprintf(stderr,"ytable is full y[%d][%d]:%d\n",row-1,col-1,y[row-1][col-1]); print_table(y,N,N); return -1; } y[row-1][col-1] = key; return build_ytable(y,row-1,col-1,row,col); }
void RestaurantPrinter::print_customers_with_at_least_budget(string minimum_budget) { Table results; if (minimum_budget == "low") { results = database_->query("*", "UserProfile", "budget = 'low' OR budget = 'medium' OR budget = 'high'"); } else if (minimum_budget == "medium") { results = database_->query("*", "UserProfile", "budget = 'medium' OR budget = 'high'"); } else { results = database_->query("*", "UserProfile", "budget = 'high'"); } print_table("Customers With Minimum Budget: " + minimum_budget, results); }
void search_all_solution(struct stack *path_list){ struct data tmp; if(!path_list) return; tmp=pop(&path_list); // when the last mass with value is checked if(tmp.step==number_of_initial_values){ printf("#%d solution\n",++n_ans); print_table(tmp.table); } // recursion search_all_solution(extend(&path_list,tmp.table,tmp.step)); }
int main(int argc, char *argv[]) { static entry_t entry[MAXENTRIES]; int nentries; if ((nentries = readentries(argv[1], entry, MAXENTRIES)) < 0) { fprintf(stderr, "Input file too large.\n"); return 1; } print_table(entry, nentries); }
int main(int argc,char *argv[]) { int y[N][N],i,j,r,c; int a[] = {9,16,3,2,4,8,5,14,12,3,2,-1}; for(i = 0;i < N;i++) for(j = 0;j < N;j++) y[i][j] = INF; for(i = 0;i < sizeof(a)/sizeof(a[0]);i++) { //printf("insert key:%d\n",a[i]); if(insert_ytable(y,N,N,a[i]) < 0) fprintf(stderr,"fail to insert key:%d\n",a[i]); //print_table(y,N,N); //printf("------------------\n"); } print_table(y,N,N); for(i = 0;i < sizeof(a)/sizeof(a[0]);++i) { //for(i = 0;i < 3;++i) { if(0 == ytable_search(y,N,N,a[i],&r,&c)) printf("ytable search %d:row:%d,col:%d\n",a[i], r,c); else printf("fail to find key:%d,row:%d,col:%d\n",a[i],r,c); } /* for(i = 0;i < sizeof(a)/sizeof(a[0]);i++) { printf("extract min:%d\n",y[0][0]); extract_min(y,0,0,N,N); } */ print_table(y,N,N); return 0; }