static void * del_element(unsigned int *seedp) { char keybuf[100]; struct ht_element *el, lookup; int x; /* pick a random element from 0 to highwater-1 */ x = my_rand(0,glob_highwater-1,seedp); sprintf(keybuf, "key%08d", x); #ifdef DEBUG printf("Removing %s", keybuf); #endif lookup.key = keybuf; el = ast_hashtab_remove_object_via_lookup(glob_hashtab, &lookup); if (el) { #ifdef DEBUG printf("...YES (el=%x)\n", (unsigned long)el); #endif free(el->key); free(el->val); free(el); els_removed++; } else { #ifdef DEBUG printf("...NO.\n"); #endif return 0; } return el; }
/*! Delete entries from the hash */ static void *hash_test_shrink(void *d) { const struct hash_test *data = d; int i; for (i = 1; i < data->preload; ++i) { char *obj = ht_new(-i); char *from_hashtab; int deleted; if (obj == NULL) { return "Allocation failed"; } from_hashtab = ast_hashtab_remove_object_via_lookup(data->to_be_thrashed, obj); deleted = from_hashtab != NULL; ht_delete(obj); ht_delete(from_hashtab); if (!deleted) { return "could not delete object"; } if (is_timed_out(data)) { return "Shrink timed out"; } } return NULL; }