I have a struct containing amongst other things a function variable that I would like to assign a function to that is itself visible on the global level, like so:
typedef struct HashMap{
struct LinkedList** datapointers;
int key_space;
int* (*hash_function)(const char*);
}HashMap;
unsigned int hashfunction(const char* input){
int i=0;
int hash=0;
while(input[i]){
hash=hash+input[i];
i++;
}
return hash;
}
//create a new hashmap
HashMap* create_hashmap(int key_space){
HashMap *hm = malloc (sizeof(HashMap));
hm->datapointers = malloc(sizeof(LinkedList)*key_space); //array of linked lists
hm->key_space=key_space;
for(int i=0;i<key_space;i++){ //initalize to NULL
hm->datapointers[i]=NULL;
}
hm->hash_function=*hashfunction;
return hm;
}
now no matter what I do I keep getting invalid pointers or undeclared variables. Is there any way to get this to work right?
Thank you