void stress_test_ht(int amt) { ht t; int i; gendata x, y; /* Just take a modulo somewhere around amt/4. */ t = ht_create((unsigned int)(amt / 4.0), num_hash); assert(ht_empty(t)); printf("Creating a hash table with %d items...\n", amt); for (i = 0; i < amt; ++i) { x.num = y.num = i; t = ht_insert_uniq(t, x, y, num_eq); assert(!ht_empty(t)); ht_lookup(t, x, num_eq, &y); assert(x.num == y.num); } y.ptr = NULL; printf("Walking a hash table of %d items...\n", amt); ht_walk(t, walker, y); printf("Deleting %d items from the hash table...\n", amt); for (i = 0; i < amt; ++i) { /* Inserting an item that's already there should fail */ x.num = i; y.num = i; /* Value does not matter */ assert(ht_insert_uniq(t, x, y, num_eq) == NULL); t = ht_delete(t, x, num_eq, NULL, NULL); } assert(ht_empty(t)); ht_destroy(t, NULL, NULL); }
int ht_die(ht *x) { if (ht_walk(x, ht_die_fn) == -1) return 1; return 0; }