/* grow the hashtable */ hashtab_t *htb_grow(hashtab_t * old_ht, size_t new_size) { /* create new hashtable */ hashtab_t *new_ht = htb_init(new_size, old_ht->hash_func); if(new_ht == NULL) return NULL; /* Iterate through the old hashtable. */ hashtab_iter_t ii; htb_iter_init(old_ht, &ii); for(; ii.key != NULL; htb_iter_inc(&ii)) htb_insert(new_ht, ii.key, ii.value); /* Destroy the old hashtable. */ htb_destroy(old_ht); return new_ht; }
/* * === FUNCTION ====================================================================== * Name: main * Description: * ===================================================================================== */ int main ( int argc, char *argv[] ) { int bucket_size = 8; htb_init(&htb, bucket_size); set(htb, "hello", "world"); set(htb, "weare", "many wei"); set(htb, "hello2", "other world"); set(htb, "hello1", "world again"); printf ( "key : hello [ %s ]\n", get(htb, "hello") ); printf ( "key : weare [ %s ]\n", get(htb, "weare") ); printf ( "key : hello1 [ %s ]\n", get(htb, "hello1") ); printf ( "key : hello2 [ %s ]\n", get(htb, "hello2") ); htb_release(htb); return EXIT_SUCCESS; } /* ---------- end of function main ---------- */