The set and map collections in this library support custom equality and comparison semantics (by accepting an IComparer<T>
or IEqualityComparer<T>
). This isn't as trivial as it sounds. Remember that these collections support specialized implementations of operations such as Intersect
and Union
, but these specialized implementations only make sense when both collections use the same equality/comparison semantics. Otherwise, the result will be corrupted.
Now, there are several general ways to handle this issue:
- Prohibit custom comparison handlers altogether. This is what F# does with its collections.
- Don't support specialized implementations at all. This is what Microsoft's BCL collections do.
- Err on the side of recklessness. Perform the specialized operations on the specified collections, without knowing whether their comparison handlers are identical. This inevitably results in data structure corruption if the comparison handlers don't match.
- Err on the side of caution. Try to determine