It is usually assumed that Equals(Object) and IEquatable<T>.Equals(T) should implement equivalence relations such that if X is considered equal to Y, and Y is considered equal to Z, and none of the elements have been changed, X can be considered equal to Z; moreover, if X is equal to Y, and Y is not equal to Z, then X can be considered not equal to Z. Methods of comparison with Wild-card and fuzzy comparisons do not implement the equivalence relationship, and therefore Equals , as a rule, cannot be implemented with such semantics .
Many collections will sort the work with objects that implement Equals in such a way that they do not implement the equivalence relationship, provided that any two objects that can be compared with each other always return the same hash code. This often requires that many things be compared unevenly in order to return the same hash code, although depending on what types of wildcards are supported, it may be possible to separate the elements to some extent.
For example, if the only wildcard supported by a particular string is “an arbitrary string of one or more digits”, you could hash the string by converting all sequences of consecutive digits and / or character characters as a string to a single character “string of digits” . If # represents any digit, then the lines abc123, ab #, abc456 and ab # 93 # 22 # 7 will be hashed to the same value as ab #, but ab # b, abc123b, etc. May hash to another value. Depending on the distribution of strings, such differences may or may not provide better performance than returning a constant value.
Note that even if one implements GetHashCode in such a way that equal objects give equal hashes, some collections may still behave strangely if the equality method does not implement the equivalence relation. For example, if the foo collection contains elements with the keys "abc1" and "abc2", attempts to access foo["abc#"] may optionally return the first element or the second. Attempts to remove the "ab #" key may arbitrarily delete one or both elements or may fail after deleting one element (its expected post-condition will not be fulfilled, since abc# will be in the collection even after removal).
Instead of comparing with jinx Equals to compare hash code equality, an alternative approach is to have a dictionary that holds for every possible line of wildcards that matches at least one line of the main collection with a list of lines that it could possibly match. Thus, if there are many lines that will correspond to ab #, they may have different hash codes; if the user enters "ab #" as a search query, the system will search for "ab #" in the wild-card dictionary and get a list of all the lines matching this template, which can then be viewed individually in the main dictionary.