I ran into this exact problem when writing a vector class. I wanted to compare vectors for equality, but float operations give rounding errors, so I wanted approximate equality. In short, redefining peers is a bad idea if your implementation is not symmetrical, reflective, and transitive.
, equals , , , . , , , B.
- , . :
var T = new Dictionary<YourType, int>()
T[a] = 0
T[c] = 1
return T[b]
Set:
var T = new HashSet<YourType>()
T.Add(a)
T.Add(c)
if (T.contains(b)) then T.remove(b)
if (T.contains(b)) then throw new Exception()
, ApproxEquals. ==, , Equals.
-, , . IApproxEquals, GetApprox , , , . 3- , .