Question

I have my class

MyClass<MyTriple<FirstG, SecondG, ThirdG>> : ICollection<MyTriple<FirstG, SecondG, ThirdG>>

I have data stored in:

Dictionary<FirstG, Dictionary<SecondG, ThirdG>> Data

and I want to implement IEqualityComparer for my Data. Constructor of MyClass has to take as argument comparer of MyTriple:

public MyClass(IEqualityComparer<MyTriple<FirstG, SecondG, ThirdG>> comparer) {...}

and I want (somehow) pass this comparer to Data and create it in constructor like:

Data = new Dictionary<FirstG, new Dictionary<SecondG, ThirdG>(SecondAndThirdGComparer)>(FirstGComparer);

I am really hopeless, I tried creating my comparer that implements IEqualityComparer, but I can't figure out, how to get FirstGComparer<FirstG> comparer. Thanks for any advices.

Was it helpful?

Solution

OK, so the user comes in with a comparer parameter (to the constructor) of type:

IEqualityComparer<MyTriple<FirstG, SecondG, ThirdG>>

Now, that could be any crazy comparer in "3D". No-one can guarantte that this comparer works in a coordinate-wise or lexicographic way. Therefore there's absolutely no way you can "factor" out a comparer of only FirstG, for example.

Suppose you have two instances firstG_X and firstG_Y, say. Then from comparer you cannot tell whether these two are equal. You can ask comparer to compare two triples only. If you "extend" firstG_X to some triple, and firstG_Y to some other triple, you have to make an arbitrary choice, and the answer from the oraculous comparer might very well depend on that choice.

Hoping what I'm saying makes sense.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top