I have the given listitem class:
class Vector
{
public int Column { get; set; }
public int Row { get; set; }
public int TableID { get; set; }
public Vector(int column, int row, int tableID)
{
TableID = tableID;
Row = row;
Column = column;
}
}
Later I have a typed list of this items, and I want to find out if a given vector (column,row,table) is already added to this list. The trivial solution of course:
var items = new List<Vector>();
items.Add(new Vector(1, 2, 3));
items.Add(new Vector(5, 6, 7));
for (int i = 0; i < 1000; i++)
{
if (items.Any(e => e.Column == 1 && e.Row == 2 && e.TableID == 3))
{
// do something
}
}
Yes it is working, but... I'm afraid as more and more items in the list it will exponential slower, as you have to enumerate all the items to find a matching one.
Finally my question is:
Can you recommend other data structure to allow "fast contains"? I mean at least linear algorithm. Any will do, I need only store 3 related int and check the containment later.