Understanding Hashing

Hey Guys

Have an issue with a hashing problem, but there is one major concept that is beating me, how to write the function!

I am trying to setup a hash function which takes distinct integer keys and a single letter e.g. {A,B,C,...} etc. The range is to be 2,000,000,000.

I am not exactly sure about how to go about writing this code exactly.

Thanks for any help

p.s. I am using namespace std and the type of data i am given looks like this 2;A , 12001;G etc
Last edited on
Post the code that you have so far using code tag.
One possibility is to hash "12001;G" etc as a string.

Somewhat more efficient would be to construct a numeric value from the int and the char and then hash that number. For example:
1
2
3
4
5
6
7
#include <functional>

std::size_t hash( int n, char c )
{
    static const std::hash<long long> h ;
    return h( n * 1000LL + c ) ;
}

Topic archived. No new replies allowed.