I want to know which is the most efficient way to store a set of list of strings in C#.
Background
My goal is to store information about "properties" like Hold(object) or Location(x,y,object). To do this I have a dictionary that map the property name to a "set of values".
For example, suppose I have a "location" set for the "location" property with these values
location -> ["1","2","robot1"]
["2","3","robot2"]
["2","5","key1"]
I want to perform query like
DB["location"].Contains(["1","2","robot1"])
I don't know if it is possible but it is to give you an idea of what I need. :)
What I have done
I have to modify and access these data frequently so I opted for an HashSet. But I have two main options:
- The first is to use something like
HashSet<string[]>. The problem is I think that HashSet cannot find duplicates because the standard behavior is to compare arrays by reference. For the same reason I don't know a good way to solve the "check if a [a,b,c] is contained in the set" problem. - The second is to use something like
HashSet<List<string>>. But I don't need a List to store a simple set of tuple. It seems to me too much for a simple job like that.
An alternative is to write my own class to store "arguments" but I don't want to do this if something exists in the standard library. :)
Thanks :)
IEqualityComparer<string[]>.HashSetof typestring[], why not create a class that encapsulates thestring[]but overridesHashCode/Equalsusing, say, the concatenation of the strings (with some delimiter). That will provide you with the desired functionality I believe. E.g. Hashcode(["1", "2", "robot1"]) == Hashcode("1 2 robot1") or something similar. (I say use a delimiter so you don't have situations like["1", "2robot1"] == ["1", "2", "robot1"]