Hash Tables - Newb to These, simple questions
Hello, I am currently messing around with hash tables and I figured the best way to do so was with other peoples hash functions to see how to go about making my own. I seem to have hit a road bump though... I just want to write something that will take in words from a list (text doc) and then pass them to the other people's hashing functions but I am not sure... I'm new to the idea of hashing so this is a tad different. I made a pointer to the functions (pointer array, actually) and I am stuck after there as to what I should do. I know I need to generate a key value to be passed to these functions, but do I just do the modulus of the total amount of words? Also, looking at these other hasing functions it looks like they only take in the key value and not the actual word itself... I also want to track the number of collisions to see which hashing function would be best to model my own future hashing function after. Any insight would be helpful. Below is what I've managed to whip together in a few minutes.
Code:
#include <iostream> aqua |
I'm not sure where you have a problem, in fact. The code looks rather correct.
I see one thing in it, however. You have three functions, each of them operated on a different range, so you can't compare them. If a hash function returns values from a wider range, you have (usually) less collisions etc. Quote:
|
Ok, I have made some changes to the program and now I run into a problem everytime one of the hash functions tries to access the key that was passed into it.
Code:
#include <iostream> |
It looks to me that your string doesn't end as expected (no zero at the end).
|
what a coincidence, i gotta turn in a project on hashing functions tomorrow in my abstract data types class
anyways i just had to hash 100 elements read in from a file (positive numbers) and i was asked to use mod7, mod51 and mod151 what i did was i used 2 unsorted linked list arrays of 7 and 51 elements. and depending on the remainder (mod) i sent each number to a different list. it works great. i also used a 151 element array to store the 100 integers with hash function "key & table_size" and if the index was already occupied i added 3 on my rehash function and modded again "(key + 3) % table_size" this worked good too. i guess the solution really depends on what you wanna use. i think the unsorted linked list is best cause you can insert and remove nodes easily with the methods let me know if you want the code to some of the functions if you decide on using unsorted linked lists or arrays, i can hook you up with the class files for the list so you can use the methods and stuff later, peace out |
All times are GMT -5. The time now is 06:56 PM. |