int main(int argc, char *argv[]) { hash_t h; hash_link_t *hl; char buf[2048]; int i; hash_init( &h, 0, 1, 2, &calc_hashnr, NULL ); while( !feof(stdin) ) { if( fgets( buf, 2048, stdin)==NULL ) break; trim(buf); hash_insert(&h, buf, strlen(buf)+1, op); } printf("---\n"); hash_dump(&h); h.nprime++; hash_expand(&h, 0); hash_dump(&h); hl=hash_sort_dump(&h); for(i=0; i<hl->used; i++) { printf("%s\n", hl->bucket[i].key); } return(0); }
void algorithm_init(struct md5_table *md5) { uint32_t i; if (hash_init(md5->num) != 0) { printf("hash init failed\n"); exit(1); } for (i = 0; i < md5->num; i++) hash_put((uint8_t *)(md5->key + i), i); hash_dump(); if (cuckoo_filter_init(md5) != 0) { printf("cuckoo init failed\n"); exit(1); } for (i = 0; i < md5->num; i++) cuckoo_filter_put((uint8_t *)(md5->key + i), &i); cuckoo_filter_dump(); if (bloom_filter_init(2500000) != 0) { printf("bloom init failed\n"); exit(1); } for (i = 0; i < md5->num; i++) bloom_filter_put((uint8_t *)(md5->key + i)); bloom_filter_dump(); }
/* * Dump the needed resources _BUT_ the colors */ void dump_needed_resources (FILE * stream, a2ps_job * job) { int i; int first = 1; multivalued_entry ** list; list = ((multivalued_entry **) hash_dump (job->status->needed_resources, NULL, NULL)); for (i = 0 ; list [i] ; i ++) { /* Don't print the colors, because they have another section */ if (strequ (list [i]-> key, "color") /* nor files, since they are yet included */ || strequ (list [i]-> key, "file")) continue; multivalued_entry_dump (stream, first, "%%%%DocumentNeededResources: %s %s\n", "%%%%+ %s %s\n", list [i]); first = false; } free (list); }
int main(int argc, char * argv[]) { hash_entry * myhash = NULL; FILE * words; int i=0, j=0, k=0, l=0, m=0; char buf[1024]; char * dictionary = "/usr/share/dict/words"; char * value_sentinel = "value_sentinel"; char * testwords[KEYS_IN_FLIGHT]; void * max_ptr; printf("Churning through %s, %d keys \"in flight\" at any given moment\n", dictionary, KEYS_IN_FLIGHT); bzero(testwords, KEYS_IN_FLIGHT * sizeof(char*)); words = fopen(dictionary, "r"); // rotate words in and out of the hash tables... while ( fgets(buf, sizeof(buf)-1, words) ) { j = strlen(buf); buf[j-1] = '\0'; if ( testwords[i%KEYS_IN_FLIGHT] != NULL ) { hash_clear(myhash, testwords[i%KEYS_IN_FLIGHT]); free(testwords[i%KEYS_IN_FLIGHT]); } testwords[i%KEYS_IN_FLIGHT] = malloc(j); strncpy(testwords[i%KEYS_IN_FLIGHT], buf, j); hash_set(myhash, testwords[i%KEYS_IN_FLIGHT], value_sentinel); i++; } /* // clear the remaining words, commented so that hash_stats(), etc. below // have something to operate on for(i=0; i<KEYS_IN_FLIGHT; i++) { hash_clear(myhash, testwords[i%KEYS_IN_FLIGHT]); free(testwords[i%KEYS_IN_FLIGHT]); } */ hash_dump(myhash); i = j = k = 0; max_ptr = NULL; hash_stats(myhash, &i, &j, &k, &max_ptr); printf("depth:\t: %d\n", hash_depth(myhash)); printf("tables\t: %d\nentries\t: %d\nnulls\t: %d\n", i, j, k); printf("sparseness\t:%f\n", hash_sparseness(myhash)); printf("max pointer\t:%p\n", max_ptr); return 0; }
static void debug_do(machine_t *machine, request_t *request, debug_flags flag){ // {{{ debug_userdata *userdata = (debug_userdata *)machine->userdata; printf("debug %s: machine: %p, request: %p, machine->name: %s\n", ( flag == DEBUG_BEFORE ) ? "before" : "after", machine, request, machine->name ); if(userdata->show_dump != 0){ hash_dump(request); } } // }}}
/* * Specify the needed resources to the PS prologue */ void dump_supplied_resources (FILE * stream, a2ps_job * job) { int i; multivalued_entry ** list; list = ((multivalued_entry **) hash_dump (job->status->supplied_resources, NULL, NULL)); for (i = 0 ; list [i] ; i ++) /* i is used as a clue that it is the first */ multivalued_entry_dump (stream, i == 0, "%%%%DocumentSuppliedResources: %s %s\n", "%%%%+ %s %s\n", list [i]); free (list); }
void scan_files (struct idhead *idhp) { struct member_file **members_0 = (struct member_file **) hash_dump (&idhp->idh_member_file_table, 0, member_file_qsort_compare); struct member_file **end = &members_0[idhp->idh_member_file_table.ht_fill]; struct member_file **members; if (largest_member_file > MAX_LARGEST_MEMBER_FILE) largest_member_file = MAX_LARGEST_MEMBER_FILE; scanner_buffer = MALLOC (unsigned char, largest_member_file + 1); for (members = members_0; members < end; members++) scan_member_file (*members); free (scanner_buffer); free (members_0); }
/* * Report content (short form) */ static void printer_table_short_self_print (struct printer_table * table, FILE * stream) { struct printer ** entries; size_t size; entries = (struct printer **) hash_dump (table, NULL, (hash_cmp_func_t) printer_hash_qcmp); for (size = 0 ; entries [size] ; size++) /* nothing */ ; lister_fprint_vertical (NULL, stream, (void *) entries, size, (lister_width_t) printer_key_len, (lister_print_t) printer_key_fputs); free (entries); }
int main(int argc, char *argv[]) { char buf[32]; char buf2[32]; int i; int len; hash_t *ht, *htcpy; hash_iter_t *iter; srand(time(NULL)); ht = hash_create(16); HASH_SET_KEYCPY(ht, _demo_dup); HASH_SET_VALCPY(ht, _demo_dup); HASH_SET_FREE_KEY(ht, _demo_destructor); HASH_SET_FREE_VAL(ht, _demo_destructor); HASH_SET_KEYCMP(ht, _demo_cmp); for (i = 0; i < 100000; ++i) { len = randstring(buf, 1, sizeof(buf) - 1); buf[len] = '\0'; len = randstring(buf2, 1, sizeof(buf2) - 1); buf2[len] = '\0'; hash_insert(ht, buf, buf2); } hash_dump(ht); htcpy = hash_dup(ht); hash_free(ht); printf("================================\n\n\n"); iter = hash_iter_new(htcpy); assert(iter); do { printf("%s=>%s\n", (char *)iter->key, (char *)iter->value); } while (hash_iter_next(iter) == 0); hash_free(htcpy); exit(0); }
static int verify_hash_table(struct hash_table *t) { unsigned int i; struct hash_elem *e; #if 0 static int count = 0; count++; if((count % 128) == 0) dprintf("verify_hash_table: count %d\n", count); #endif // do a quick spin through the table, making sure the same element isn't double entered for(i = 0; i < t->table_size; i++) { for(e = t->table[i]; e != NULL; e = NEXT(t, e)) { if(find_in_table(t, e, i, NEXT(t, e)) == true) { hash_dump(t); panic("element %p double inserted into hash table %p\n", e, t); } } } return 0; }
/* * Clean all memory on exit to help find leaks * Yeah I know, one big ugly function -Druid * Added to AFKMud by Samson on 5-8-03. */ void cleanup_memory( void ) { int hash; #ifdef IMC fprintf( stdout, "%s", "IMC2 Data.\n" ); free_imcdata( true ); imc_delete_info( ); #endif fprintf( stdout, "%s", "Quote List.\n" ); free_quotes( ); fprintf( stdout, "%s", "Random Environment Data.\n" ); free_envs( ); fprintf( stdout, "%s", "Auction Sale Data.\n" ); free_sales( ); fprintf( stdout, "%s", "Project Data.\n" ); free_projects( ); fprintf( stdout, "%s", "Ban Data.\n" ); free_bans( ); fprintf( stdout, "%s", "Auth List.\n" ); free_all_auths( ); fprintf( stdout, "%s", "Morph Data.\n" ); free_morphs( ); fprintf( stdout, "%s", "Rune Data.\n" ); free_runedata( ); fprintf( stdout, "%s", "Connection History Data.\n" ); free_connhistory( 0 ); fprintf( stdout, "%s", "Slay Table.\n" ); free_slays( ); fprintf( stdout, "%s", "Holidays.\n" ); free_holidays( ); fprintf( stdout, "%s", "Specfun List.\n" ); free_specfuns( ); fprintf( stdout, "%s", "Wizinfo Data.\n" ); clear_wizinfo( ); fprintf( stdout, "%s", "Skyship landings.\n" ); free_landings( ); fprintf( stdout, "%s", "Ships.\n" ); free_ships( ); fprintf( stdout, "%s", "Overland Landmarks.\n" ); free_landmarks( ); fprintf( stdout, "%s", "Overland Exits.\n" ); free_mapexits( ); fprintf( stdout, "%s", "Mixtures and Liquids.\n" ); free_liquiddata( ); fprintf( stdout, "%s", "DNS Cache data.\n" ); free_dns_list( ); fprintf( stdout, "%s", "Local Channels.\n" ); free_mudchannels( ); // Helps fprintf( stdout, "%s", "Helps.\n" ); free_helps( ); // Commands fprintf( stdout, "%s", "Commands.\n" ); free_commands( ); #ifdef MULTIPORT // Shell Commands fprintf( stdout, "%s", "Shell Commands.\n" ); free_shellcommands( ); #endif // Socials fprintf( stdout, "%s", "Socials.\n" ); free_socials( ); // Languages fprintf( stdout, "%s", "Languages.\n" ); free_tongues( ); // Boards fprintf( stdout, "%s", "Boards.\n" ); free_boards( ); // Events fprintf( stdout, "%s", "Events.\n" ); free_all_events( ); // Find and eliminate all running chess games fprintf( stdout, "%s", "Ending chess games.\n" ); free_all_chess_games( ); // Whack supermob fprintf( stdout, "%s", "Whacking supermob.\n" ); if( supermob ) { supermob->from_room( ); charlist.remove( supermob ); deleteptr( supermob ); } // Free Characters fprintf( stdout, "%s", "Characters.\n" ); extract_all_chars( ); // Free Objects fprintf( stdout, "%s", "Objects.\n" ); extract_all_objs( ); // Descriptors fprintf( stdout, "%s", "Descriptors.\n" ); free_all_descs( ); // Deities fprintf( stdout, "%s", "Deities.\n" ); free_deities( ); // Clans fprintf( stdout, "%s", "Clans.\n" ); free_clans( ); // Races fprintf( stdout, "%s", "Races.\n" ); free_all_races( ); // Classes fprintf( stdout, "%s", "Classes.\n" ); free_all_classes( ); // Teleport lists fprintf( stdout, "%s", "Teleport Data.\n" ); free_teleports( ); // Areas - this includes killing off the hash tables and such fprintf( stdout, "%s", "Area Data Tables.\n" ); close_all_areas( ); // Get rid of auction pointer MUST BE AFTER OBJECTS DESTROYED fprintf( stdout, "%s", "Auction.\n" ); deleteptr( auction ); // Title table fprintf( stdout, "%s", "Title table.\n" ); free_all_titles( ); // Skills fprintf( stdout, "%s", "Skills and Herbs.\n" ); free_skills( ); // Prog Act lists fprintf( stdout, "%s", "Mudprog act lists.\n" ); free_prog_actlists( ); // Questbit data fprintf( stdout, "%s", "Abit/Qbit Data.\n" ); free_questbits( ); free_mssp_info(); fprintf( stdout, "%s", "Checking string hash for leftovers.\n" ); { for( hash = 0; hash < 1024; ++hash ) hash_dump( hash ); } #if !defined(__CYGWIN__) && defined(SQL) fprintf( stdout, "%s", "Closing database connection.\n" ); close_db( ); #endif // Last but not least, close the libdl and dispose of sysdata - Samson fprintf( stdout, "%s", "System data.\n" ); dlclose( sysdata->dlHandle ); deleteptr( sysdata ); fprintf( stdout, "%s", "Memory cleanup complete, exiting.\n" ); }
int main(int argc, char **argv) { hash *h=hash_retrieve(argv[1]); hash_dump(h); return 0; }