void hash_resize(hash_type *hash, int new_size) { hash_sll_type ** new_table = hash_sll_alloc_table( new_size ); hash_node_type * node; uint32_t i; for (i=0; i < hash->size; i++) { node = hash_sll_get_head(hash->table[i]); while (node != NULL) { uint32_t new_table_index = hash_node_set_table_index(node , new_size); hash_node_type *next_node = hash_node_get_next(node); hash_sll_add_node(new_table[new_table_index] , node); node = next_node; } } /* Only freeing the table structure, *NOT* calling the node_free() functions, which happens when hash_sll_free() is called. */ { for (i=0; i < hash->size; i++) free( hash->table[i] ); free( hash->table ); } hash->size = new_size; hash->table = new_table; }
hash_node_type * hash_node_alloc_new(const char *key, node_data_type * data, hashf_type *hashf , uint32_t table_size) { hash_node_type *node; node = (hash_node_type*) util_malloc(sizeof *node ); node->key = util_alloc_string_copy( key ); node->data = data; node->next_node = NULL; node->global_index = hashf(node->key , strlen(node->key)); hash_node_set_table_index(node , table_size); return node; }