0

I am using DJB2 hash function in my hashing program where I want to store strings. But this hash function returns a very large unsigned int value as return value(hash table index). If my table size is very small (say 13), is there any way to convert this large value into smaller one. All I want to avoid collision as much as possible.

The DJB2 hash function code is as follows:

unsigned int djb_hash(string s)
{
    int i;
    unsigned int h;
    h = 5381;

    for (i = 0; i < s.size(); i++) 
    {
        h = (h << 5) + h + s[i];
    }

    return h;
}
bytecode77
  • 14,163
  • 30
  • 110
  • 141
user4650623
  • 17
  • 2
  • 11

1 Answers1

0

If you want to convert larger value into smaller one, then there is more chances of collision. Larger string is the good enough to avoid collision.

Musakkhir Sayyed
  • 7,012
  • 13
  • 42
  • 65