Sure, hascodes are used in hastables and collections but what about that:
class TwoDPoint : System.Object{
public readonly int x, y;
//...left out some code
public override int GetHashCode(){
return x ^ y;
}
}
Source: https://msdn.microsoft.com/en-us/library/ms173147(VS.80).aspx
The snipped above directed me to the following sentence:
You should not assume that equal hash codes imply object equality.
Source: https://msdn.microsoft.com/de-de/library/system.object.gethashcode(v=vs.110).aspx
What I wonder is if we shouldn't always check for object equality after two hash codes match. Consider the following two dots:
P1.x = 2; P1.y = 4; Hash = 16
and
P2.x = 4; P2.y = 2; Hash = 16
- If I only check the hash before inserting an item into a hashtable
wouldn't that be a huge problem?
- Or is the this function maybe
just used to provide a more performant way of checking "simmilarity"
but always requires an equality check after a match?
- Or should I not care and just use the hashcode and assume it doesn't matter?