Question: I am doing some financial trading work. I have a set of stock symbols but they have very clear pattern:
it's composed of two characters `AB`, `AC` `AD` and current month which is a four digit number: `1503`, `1504`, `1505`. Some examples are:

```
AB1504
AB1505
AC1504
AC1505
AD1504
AD1505
....

```

Since these strings are so well designed patterned, I want to map (hash) each of the string into a unique integer so that I can use the integer as the array index for fast accessing, since I have a lot of retrievals inside my system and `std::unordered_map` or any other hash map are not fast enough. I have tests showing that general hash map are hundred-nanoseconds latency level while array indexing is always under 100 nanos.
my ideal case would be, for example, `AB1504` maps to integer `1`, `AB1505`
maps to `2`...., then I can create an array inside to access the information related to these symbols much faster.
I'm trying to figure out some hash algorithms or other methods that can achieve my goal but couldn't find out. 
Do you guys have any suggestions on this problem?

Answer: 
You can regard the string as a variable-base number representation, and convert that to an integer. For example:

```
AC1504:
A (range: A-Z)
C (range: A-Z)
15 (range: 0-99)
04 (range: 1-12)

```

Extract the parts; then a hash function could be

```
int part1, part2, part3, part4;
...
part1 -= 'A';
part2 -= 'A';
part4 -= 1;
return (((part1 * 26 + part2) * 100 + part3) * 12 + part4;

```
If you parse the string as a mixed base number, first 2 base-26 digits and then 4 base-10 digits you will quickly get a unique index for each string. The only issue is that if you might get a sparsely populated array. 

You can always reorder the digits when calculating the index to minimize the issue mentioned above.

As the numbers are actually months I would calculate the number of months from the first entry and multiply that with the 2 digit base-26 number from the prefix.

Hope you can make some sense from this, typing on my tablet at the moment. :D