c - Numbers of collision in a hash table -


i'm doing hash table store elements in range: 2000000-20000000 of values.

examples: 17664658-8,7587458-8,7338375-4,5741259-2.....

in sample of 100000 elements number of collisions 23939 , in sample of 1000000 elements number of collisions 439870. don't know hash tables, numbers of collisions not little high?

i read in controlled range of numbers can have hash function uniform , not know how or start , advice ?

this hash fuction.

int hash(char* clave,int m) { //m size of table (about double of elements stored)         int number=0,i=0;         ///          while(isdigit(clave[i])){ //i don't use last 2 characters.              number+=(clave[i++]-'0');             if(isdigit(clave[i]))                 number*=10;         }         /// mutiplication method         float dis,r;         r=0.6106154;         dis = r*(number) - floor(r*(number));         int result = (int)(dis*m);         return result;     } 

no, number of collisions not high, in fact it's you'd expect. formula expected number of collisions in hash table uniform, random hash function , m buckets , n insertions is:

n - m * (1 - ((m-1)/m)^n) 

for case:

m = 178144 n = 100000 

plugging numbers in gives:

100000 - 178144 * (1 - ((178144-1)/178144) ^ 100000) = 23476.674 

and observed number of collisions 23939. there nothing wrong hash function.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -