|
|
|
@ -74,11 +74,11 @@ hashtable_int *hashtableCreate(size_t size, size_t (*hashfunc)(unsigned int)) |
|
|
|
|
size = (size_t)next_power_of_two((unsigned int)size); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
hashtbl=(hashtable_int*)malloc(sizeof(hashtable_int)); |
|
|
|
|
hashtbl=(hashtable_int*)malloc(sizeof(hashtable_int)); |
|
|
|
|
if (!hashtbl) |
|
|
|
|
return NULL; |
|
|
|
|
|
|
|
|
|
hashtbl->nodes=(hashnode_i**)calloc(size, sizeof(struct hashnode_i*)); |
|
|
|
|
hashtbl->nodes=(hashnode_i**)calloc(size, sizeof(struct hashnode_i*)); |
|
|
|
|
if (!hashtbl->nodes) |
|
|
|
|
{ |
|
|
|
|
free(hashtbl); |
|
|
|
@ -136,7 +136,7 @@ int hashtableInsert(hashtable_int *hashtbl, KeyType key, void *data) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
node=(hashnode_i*)malloc(sizeof(struct hashnode_i)); |
|
|
|
|
node=(hashnode_i*)malloc(sizeof(struct hashnode_i)); |
|
|
|
|
if (!node) |
|
|
|
|
return -1; |
|
|
|
|
node->key=key; |
|
|
|
@ -168,7 +168,7 @@ int hashtableInsertHashed(hashtable_int *hashtbl, KeyType key, void *data) |
|
|
|
|
node=node->next; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
node=(hashnode_i*)malloc(sizeof(struct hashnode_i)); |
|
|
|
|
node=(hashnode_i*)malloc(sizeof(struct hashnode_i)); |
|
|
|
|
if (!node) |
|
|
|
|
return -1; |
|
|
|
|
|
|
|
|
@ -242,7 +242,7 @@ int hashtableResize(hashtable_int *hashtbl, size_t size) |
|
|
|
|
newtbl.size=size; |
|
|
|
|
newtbl.hashfunc=hashtbl->hashfunc; |
|
|
|
|
|
|
|
|
|
newtbl.nodes=(hashnode_i**)calloc(size, sizeof(struct hashnode_i*)); |
|
|
|
|
newtbl.nodes=(hashnode_i**)calloc(size, sizeof(struct hashnode_i*)); |
|
|
|
|
if (!newtbl.nodes) |
|
|
|
|
return -1; |
|
|
|
|
|
|
|
|
@ -311,7 +311,7 @@ void hashtablePrint(hashtable_int *hashtbl) |
|
|
|
|
for (node=hashtbl->nodes[n]; node; node=next) |
|
|
|
|
{ |
|
|
|
|
next = node->next; |
|
|
|
|
std::cout<<"Key : "<<node->key<<", Data : "<<node->data<<std::endl; |
|
|
|
|
std::cout<<"Key : "<<node->key<<", Data : "<<node->data<<std::endl; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|