In what case `x===y` and `objectid(x) == objectid(y)` are not interchangable?

I was reading the official documentation and found the following statement about objectid:

If x === y then objectid(x) == objectid(y) , and usually when x !== y , objectid(x) != objectid(y) .

It seems that there are edge cases where objectid(x) == objectid(y) does not imply x===y.

Does anyone know when this can happen (aside from redefining methods for ==)? Thanks!

1 Like

The objectid is a hash value, which has the same limitation as other hash values. That is, there are a potentially infinite number of values but only a finite number of UInt hashes. This edge case would then be a hash collision, where two unique values happen to have the same hash.

5 Likes

Thanks! This makes sense. Does === double-check the identity of two comparing objects even if their hash values obtained from objectid are the same?

You’re welcome! For some definition of “identity” (as defined by the === docstring), yes!

1 Like