哈希表创建
#include <stdio.h>
#include <stdlib.h>
#include "hash.h"
HashTable* create_hash(int size){
HashEntry **ha = (HashEntry**)malloc(sizeof(HashEntry*)*size);
if(!ha){
free(ha); //感觉并不是很必要的,
return NULL;
}
memset(ha, 0, sizeof(HashEntry*)*size);
HashTable *hashtable = (HashTable*)malloc(sizeof(HashTable));
if(!hashtable) {
free(hashtable);
return NULL;
}
memset(hashtable, 0, sizeof(HashTable));
hashtable->bucket = ha;
hashtable->size = size;
hashtable->last_error = HASH_OK;
return hashtable;
}