For now I am just trying to implement a hash table and a simplified version to see it work. Each entry has a key and a value and a pointer (in case of collisions it is a linked list)
Then the hash table is an array of those entries. I started initializing the table and printing it out just to make sure things are working. I don't think I'm using malloc correctly for array of structures because I keep getting segmentation fault core dump as an error.
help
Code:
#define TABLE_SIZE ((int) 10)
struct entryhash
{
int key; //order of nodes will be string later to match other stuff
double num; //entry is another structure, replace with double for now?
struct entryhash * next; //linked structure in case of collision
};
typedef struct entryhash hash_item;
void print_table (hash_item **head,int tablelen){
int i;
hash_item *curr;
for (i=0; i <tablelen; i++){
curr=head[i];
printf("%d\n", curr->key);
//printf("%lf\n", curr->num);
}
}
int main(){
hash_item ** newhash;
newhash = (hash_item **)malloc(sizeof(hash_item*) * TABLE_SIZE);
//initialize everything to null?
int i;
for (i=0; i<TABLE_SIZE; i++){
newhash[i]->key= -1;
newhash[i]->next=NULL;
}
print_table(newhash, TABLE_SIZE);
//add entries
//add_hash_el( &newhash, 9,2.5);
return 0;
}