#include "uthash_SFH.h" #include /* malloc */ #include // BEGIN HARNESS void reach_error() { assert(0); } void __VERIFIER_assert(int cond) { if (!cond) { reach_error(); } } // END HARNESS typedef struct example_user_t { int id; int cookie; UT_hash_handle hh; } example_user_t; int main() { int i; example_user_t *user, *tmp, *users=NULL; /* create elements */ for(i=0; i<1000; i++) { user = (example_user_t*)malloc(sizeof(example_user_t)); if (user == NULL) { exit(-1); } user->id = i; user->cookie = i*i; HASH_ADD_INT(users,id,user); } /* delete each ID */ for(i=0; i<1000; i++) { HASH_FIND_INT(users,&i,tmp); if (tmp != NULL) { HASH_DEL(users,tmp); free(tmp); } else { reach_error(); } } /* show the hash */ for(user=users; user != NULL; user=(example_user_t*)(user->hh.next)) { reach_error(); } example_user_t* temp; HASH_ITER(hh, users, user, temp) { HASH_DEL(users, user); free(user); } return 0; }