A few days ago i posted about my hash table template.. i given up on it to make smaller functions which were easier, and it compiled with no problem. The problem I'm having is after testing the program with two elements into the hash table, the third additional element bugs the data structure.
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 = hash_key;
entry_array->table[h] = Cur;
return 0;
}
else
{
struct _node * it;
while(entry_array->cursor < entry_array->size && entry_array->table[entry_array->cursor] != NULL)
++entry_array->cursor;
if( entry_array->cursor == entry_array->size)
return 1;
struct _node * Cur = (_node *)malloc(sizeof(_node));
Cur->object = object;
Cur->key = hash_key;
entry_array->table[entry_array->cursor] = Cur;
it = entry_array->table[h];
while(it->next != NULL)
it = it->next;
it->next = entry_array->table[entry_array->cursor];
return 0;
}
return 1;
}