I am checking if a total group of edges already contains the connection between 2 points.
I want to use HashSet
's that will contain 2 vectors as Dictionary
keys. Then I want to be able to call a performant Dictionary.ContainsKey(hashSet)
. I want the contains/equality check to be dependent on the Vectors in the Set.
Fex. If I add HashSet [V000 V001]
to the Dict. I want to get Dictionary.ContainsKey(HashSet [V001 V000])
return true. (HashSet, so the order can vary, just the same Elements)
The Problem seems to be, that the Dictionary.ContainsKey()
method does see separately created HashSets
as different objects, even though, they contain the same elements.
Dictionary<HashSet<Vector3>, Vector3> d = new Dictionary<HashSet<Vector3>, Vector3>();
HashSet<Vector3> s = new HashSet<Vector3>();
s.Add(Vector3.one);
s.Add(Vector3.zero);
d.Add(s);
HashSet<Vector3> s2 = new HashSet<Vector3>();
s2.Add(Vector3.zero);
s2.Add(Vector3.one);
bool doesContain = d.ContainsKey(s2); // should be true
You also may suggest a better way of doing this 'Contains()' check efficiently.