I have the following code:
template <int size>
inline uint hashfn( const char* pStr )
{
uint result = *pStr;
switch ( size )
{
case 10:
result *= 4;
result += *pStr;
case 9:
result *= 4;
result += *pStr;
...
...
case 2:
result *= 4;
result += *pStr;
}
return result;
}
This code is a hash function for DNA sequences of certain lenghts where the length is a template parameter. It is an unrolled loop with a switch statement to jump in at the right spot. The size is however a constant since it is a template parameter. Could I specialize this for certain size values? Maybe with something like:
template <int 2>
inline uint hashfn( const char* pStr )
{
uint result = *pStr;
result *= 4;
++pStr;
result += *pStr;
return result;
}