Creating a simple hash system

I am trying to create a database system where I can retrieve an index based on a string key. Each person has their own entry in the file based on a unique id# that each person has which ranges from 1 to 999999. I will use this id# as the key for lookup. I can use it in the form of a string or an integer; "12433" or 12433. I want a hash function to tell me a unique index\file position where I can save\retrieve the persons data.

I'm trying to avoid collisions at all costs so I am trying to limit my entries to a fraction of the total tablesize (max index value) Will this help?

Tablesize=100000 (max index value / table size)
MaxEntries=5000 (max entries Ill actually have)

Suppose A is a first timer, id=3478734, using the hash to determine his position in the file. Hash(3478734) = 2411. I will then fseek( 2411*sizeof(struct) ) to retrieve\store the persons data from a binary file.

I read through numerous web pages and pdf files but every algorithm I try I get numerous collisions (900+1300 range). Any help is appreciated
Last edited on
Hash tables are designed on the assumption that hash collisions are an every day occurrence. The hash is just used to narrow down the search to a few possibilities, and from there you just use a normal search algorithm to get what you're looking for.
Last edited on
(id - 1 ) * sizeof( struct ) ?

Only way to eliminate collisions....
Topic archived. No new replies allowed.