First of all, be careful when declaring a class/struct member as a pointer. It should always be clear who owns what and you can't simply set a pointer to some random address and expect things to work out. So for example, the node_ class should really be using an std::string in place of a raw pointer.
Code:
typedef struct _instant_hashtable_t
{
struct _node **table;
size_t size;
size_t cursor;
}_instant_hash;
For C++, you can simply do this:
Code:
struct _instant_hash
{
_node **table;
size_t size;
size_t cursor;
};
Suggestion:
Code:
int HashTable_insert( const char * hash_key, void * object, _instant_hash * entry_array)
{
unsigned int h = SuperFastHash(hash_key, strlen(hash_key)) % entry_array->size;
if(entry_array->table[h] == NULL)
{
struct _node * Cur = (_node *)malloc(sizeof(_node));
Cur->object = object;
Cur->key = (char*)malloc(strlen(hash_key) + 1);
Cur->next = NULL;
strcpy(Cur->key, hash_key);
entry_array->table[h] = Cur;
return 0;
}
else
{
_node * it = entry_array->table[h];
while(it->next)
{
if(strcmp(it->key, hash_key) == 0)
{
// if the object already exists, return 1.
// otherwise, reset object and return 0.
}
it = it->next;
}
struct _node * Cur = (_node *)malloc(sizeof(_node));
Cur->object = object;
Cur->key = (char*)malloc(strlen(hash_key) + 1);
strcpy(Cur->key, hash_key);
Cur->next = NULL;
it->next = Cur;
return 0;
}
return 1;
}
void* HashTable_search(const char * hash_key, _instant_hash *entry_array)
{
unsigned int h = SuperFastHash(hash_key,strlen(hash_key)) % entry_array->size;
if ( entry_array->table[h] != NULL )
{
struct _node *it;
/* Search the chain at index h */
for ( it = entry_array->table[h]; it != NULL; it = it->next )
{
if ( strcmp(it->key, hash_key) == 0 )
return it->object;
}
}
return NULL;
}