C/C++ >> Need help to complete pressed for time (NEW)
Posted by speedy11 on 00:47:00 10-07-2001


[ This Message was edited by: speedy11 on 2001-10-10 23:55 ]
Posted by fsvara on 18:36:00 10-08-2001
i don't know - i don't understand it either...

i wonder why the c-gods here don't say anything...
Posted by SilentStrike on 18:42:00 10-08-2001
Repost with HTML disabled... it's obscuring some of your code.
Posted by SilentStrike on 18:47:00 10-08-2001
Also... what does this mean? The sentence seems broken.

"Therefore, donot assume that the available empty. It is filled, store the student details in the first empty position after the generated hash index. "

Posted by speedy11 on 20:18:00 10-08-2001


[ This Message was edited by: speedy11 on 2001-10-10 23:56 ]
Posted by SilentStrike on 21:46:00 10-08-2001
Yeah... this way of inserting them definietely is a problem..

"Therefore, donot assume that the array position is empty. It is filled, store the student details in the first empty position after the generated hash index. "

Because then the hash codes are really meaningless. Let's say a given name hashes to 10... usually this will mean that the name is in the 10th element of the hash, however, such is not true with that algorithm. Perhaps modify the algorithm such that you are using an array of linked lists. The hash will return a linked list, which is then linearly searched (but the number of things in any given linked lists will be small, so it's not that costly).

I haven't really ever coded in C, only C++, but here is my guess as to how it would be done in C (using void pointers rather than templates for holding data... ick ).

struct pair {
char* key;
char* value;
}


list hashTable[maxNum];


void insert(char* key, char* value) {
int index = hash(key) % (maxNum - 1);
list listThisOneShouldBeIn = hashTable[key % (index - 1)];
//insert key/value pair into list
}

char* find(char* key) {
int index = hash(key) % (maxNum - 1);
list listToSearch = hashTable[key % (index - 1)];
// search listToSearch's pairs until you find given key in list
Posted by SilentStrike on 21:50:00 10-08-2001
Gah, nevermind... yeah, I know what your teacher wants you to do now.

Basically, keep the idea of storing the pairs, but just use an array of pairs, not an array of list of pairs The hash will just let you "cheat" in a linear search of an array by not starting at the beginning. To find a value, start at the index given by the hash mod, and continually checking the key (strcmp) of each index, incrementing by one until you find it. You may also wish to wrap your search around by modding it by the final value... but that gets more complex.

Essentially, your teacher is making you write some funky ass hash table that lollipops when searching for something not in the list (have to check every element).
Posted by Sebi on 05:39:00 10-10-2001
i didn't really get that code either...