Good Hashing code for a string

I need a basic hashing code for a string of the form '9X9XX99X9XX999999' where 9 represents any digit and X represents any letter (capitals A-Z only).

Should be a quick 75 points for someone...
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What do you mean by a basic hashing code ?

How big do you want your hash table to be ?

You could just add up all the characters (their ASCII values) ...
bombboyerAuthor Commented:
I'd like the hashing table to be as small as possible (ie. not a sparse array). I don't need "exact fit" small, but decently "tight"...
What is the data that is gonna be put in the hash table ? What are its properties ? Anything special, or 100% probabilistic ?

Does the data need to be persistent in the hash table, or can it be erased on collision (like a cache) ?

How many entries do you foresee into the hash table ? Any clustering you think could happen ?
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Java uses the following computation for hashing strings:

You might want to restrict it to a limited number of characters if its uniqueueness is liable to be at the beginning of the string.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
One good hash scheme, used by Borland's compilers:

BigPrime := 1009;
Tot := 0;

for i := 1 to Length( Token )      Tot += Tot * 13 + Token[i];

Tot %=  BigPrime;

If the strings contain '9' and 'X' only you might calculate the hash by setting bit i to 1 if the key[i] == '9' or bit i to 0 if key[i] == 'X' (or vice versa).

  enum {  MAX_HASH = 1023 };
  unsigned int hash = 0;
  for (int i = 0; i < strlen(key); ++i)
       if (key[i] == '9')
            hash  |= 1<<(i % 32);
   hash = (hash * 13) / 7;  
   hash %= MAX_HASH;

The for loop calculates a unique number for any key that has a length of less than 33. By multiplying it with 13/7 we eliminate bad hashing if for example most keys would end with '9'.

Regards, Alex
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.