Hashed map/set of Arc efficiency

This works. But it is comparing the entire contents of "Item", as you can see from here:

Suppose "Item" is a very big object (a graphics mesh in my case). I want to have a set or hash of the object identity (the 'address' of course) inside the Arc, without hashing the entire contents of the object. Is there some way to safely do that?

Address identity gets a lot messier with zero-sized types/type-erased types/generic types/more than one type, but if we're just talking about Arc<KnownThing> where KnownThing is Sized and not a ZST, you can implement Hash yourself and hash the address of the KnownThing.

You'll also need to do the analogous thing for Eq and PartialEq and maybe Ord and whatnot.

You can't override the implementation of Arc<_> itself, so you would need to do these things on KnownType or a newtype or other container of the Arc.

Or perhaps a generic wrapper of KnownType since "Foo" != "Foo" is surprising.


Another option besides newtypes is to use hashbrown's HashTable which lets one use custom hashing and equality functions.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.