I have an array of fingerprints in hash buckets. I would like to insert into the bucket and search on it with out going from entry 0 to entry n.
What i want to do is, when i add entries into the buckets i use the fingerprint as an input to calculate a hash which i can use to determine which bucket to add into. This was not difficult, but when i try to hash the fingerprint using the same algorithm to identify into which slot in the bucket to add the fingerprint i see that it makes a lot of collisions.
Here is the code i used to hash the fingerprints into the buckets. I tried to use the same code with more characters but it still gives me higher collision.
he.fingerprint is 33 characters wide
number of buckets is 1024
number of entries per bucket is 2048
char hph[32];
int bk,en;
unsigned long h = 0, g,i=0;
int j=0;
strncpy(hph,(const char*)(he).fing_print,32);
while ( j<32 )
{
h =h + hph[j]++;
g = h & 0xFFf00000;
h ^= g >> 24;
h &= ~g;
j++;
}
bk=h%buckets;
en=h%entries_per_bk;