How to achieve collision-free "hash codes" in one single Julia session?

I have many mixed composite-type instances that I need to compare their equality (by ===) when I don’t necessarily (want to) have access to them directly.

I do not want to directly store a reference (like Ref or a struct) pointing to the original object because, I would have to manually free these references to allow garbage collection.

So far, what I have done is storing the hash values of them using objectid in separate containers for comparison. However, I would like to avoid possible hash collision so that I can guarantee the equality of two objects when their hash codes (or other homogenous identifiers that are not strictly hash codes) are the same.

Is there any efficient way to achieve this? Thanks very much!

You can store a WeakRef, and compare them via their .value component. Hashes can’t be guaranteed to not collide, although it happens infrequently.

1 Like

This seems like a good middle-way solution. Thanks!