I have two methods like this
HashSet<Tuple<int,int>> _xyPairs = new HashSet<Tuple<int,int>>();
private void SetTravelled(int x, int y, bool travelled)
{
var t = new Tuple<int, int>(x, y);
if (travelled)
_xyPairs.Add(t);
else
_xyPairs.Remove(t);
}
private bool HaveTravelled(int x, int y)
{
return _xyPairs.Contains(new Tuple<int, int>(x, y));
}
I don’t mind the first method so much because it’s not called very often. The second method however is called very frequently. So I have to create new Tuple’s over and over.
Is there a way to combine the two integers into one value for the Hashset?
If you have an indication that the tuple is actually causing you a problem, you could try to combine the two 32-bit integers into one 64-bit integer: