The history why is long, but the problem is simple. Having 3 strings I need to cache the matching value. To have a fast cache I use the following code:
public int keygen(string a, string b, string c)
{
var x = a + "@@" + b + "@@" + c;
var hash = x.GetHashCode();
return hash;
}
(Note that string a
,b
,c
does not contain the code "@@"
)
The cache it self is just a Dictionary<int, object>
I know there is a risk that the hash key might be non unique, but except this:
Does anyone know a faster way to make an int key? (in C#) This operation takes ~15% of total CPU time and this is a long running app.
I have tried a couple of implementations but failed to find any faster.