Can someone point me towards a dead basic, complete example of a hash table utilising chaining? I've got a working hash function, I am just getting really frustrated with not understanding what I don't understand with the setting up of the hash table. All the examples on the web I've looked at I can't get working, or they seem so complicated; pages and pages of code seeing how well it works, and on various inputs, and I just want something dead simple and transparent, that will not crash when I give it a word.
My understanding is that for the hash table with chaining, you'll need a linked list data structure (which I have working fine) and another data structure, that holds each chain and also an index. So I have something like
typedef struct l {
char* data;
int numfound;
struct l *next;
} listelem;
for my linked list, which seems to work well, but I am stuck on what to do for the other data structure. Should it be
typedef struct hashtable {
struct listelem chain;
int index;
} hashtable;
or is that way off base?
The problem I'm having is that I'm developing in Windows at the moment, and when it doesn't work it just crashes, with no inkling of what went wrong, whereas on linux it seems to be easier to catch errors. Or it gives me thousands of errors/warnings on compile, and I can't resolve them.
I've written about three or four insert functions now, using different ideas and bases, and none of them have worked even a little bit. My current m.o. for the insert function is planned thusly:
// 1. hash word, get address
// 2. compare to word in that address, if there is one
// 3. if there is one, check it until next is null
// 4. check by strcmp-ing the data segment and the input string
// 5. if there is no match, add it to the beginning of the chain
// 6. if there is a match, increment the numfound and break
Does that sound reasonable?
Ach. My project is due on Friday and I'm so far behind.. Please help me, good people! I am talking to my tutor tomorrow, hopefully I can get some of this resolved, but I am in a sorry state -- programming six hours a night after an exhausting day just isn't going well. No sleep = no energy = sloppy programming = staying up to fix errors = no sleep, etc.
sad face.