static void initialize(pp_linkset *ls, int size) { ls->hash_table_size = size*LINKSET_SPARSENESS; ls->population = 0; ls->hash_table = (pp_linkset_node**) malloc (ls->hash_table_size*sizeof(pp_linkset_node *)); clear_hash_table(ls); }
void collate_vnums(FILE * in_file) { int vnum; char * line; int line_size; int min_vnum=65000; int max_vnum=0; hash_entry * entry; line=malloc(BUF_SIZE); line_size=BUF_SIZE; for ( ; ; ) { getline(&line, &line_size, in_file); if (line[0] != '#') continue; vnum=atoi(line+1); if (vnum==0) break; if (vnum > max_vnum) max_vnum=vnum; if (vnum < min_vnum) min_vnum=vnum; add_vnum(vnum); } if (max_vnum != 0) { for (vnum=min_vnum; vnum <= max_vnum; vnum++) { if ( (entry=get_hash_entry(vnum)) != NULL && entry->offset>=0 ) { if ( entry->offset == 0 ) printf(" %i\n",entry->vnum); else printf(" %i-%i\n",entry->vnum,entry->vnum+entry->offset); } } } clear_hash_table(); free(line); }
void pp_linkset_clear(pp_linkset *ls) { /* clear dangling linked lists, but retain hash table itself */ int i; pp_linkset_node *p; if (ls==NULL) return; for (i=0; i<ls->hash_table_size; i++) { p=ls->hash_table[i]; while (p) { pp_linkset_node *q = p; p=p->next; xfree((void*) q, sizeof(pp_linkset_node)); } } clear_hash_table(ls); ls->population=0; }
END_TEST START_TEST (ut_hash_table_insert_and_delete) { init_hash_table(test_hash_table, DEFAULT_SIZE); wchar_t c; int i; Node *result; for (c = L'a'; c <= L'z'; c++) { insert_node_hash_table(test_hash_table, c); } for (c = L'a'; c <= L'z'; c++) { delete_node_hash_table(test_hash_table, c); } ck_assert_msg(test_hash_table->array->total == 0, "%d\n", test_hash_table->array->total); ck_assert_msg(test_hash_table->array->size == 2, "%d\n", test_hash_table->array->size); clear_hash_table(test_hash_table); }
END_TEST START_TEST (ut_hash_table_insert_and_lookup) { init_hash_table(test_hash_table, DEFAULT_SIZE); wchar_t c; int i; Node *result; for (c = L'a'; c <= L'z'; c++) { insert_node_hash_table(test_hash_table, c); } for (c = L'a'; c <= L'z'; c++) { result = lookup_node_hash_table(test_hash_table, c); if (result != NULL) ck_assert_msg(result->key == c, "%c != %c", result->key, c); else ck_abort_msg("Couldn't find character %c", c); } ck_assert_msg(test_hash_table->array->total == 26); ck_assert_msg(test_hash_table->array->size == 32); clear_hash_table(test_hash_table); }