Consider the following situation:
- We have a hash map from a generic key type
K, to some value type
Vthat we control.
- The value type
Vis some type of reference counted pointer.
- All keys map to different pointers, that is, given two different keys
k2, the values
map[k2]are also different.
Given the above, is it possible to store a clone of the reference counted value and some extra information such that you can find the value in the hash map and remove it? Obviously, you can do this by just storing a clone of the key, but this requires that
K is clone. If we could somehow store a copy of the hash of
K instead, then we should still be able to look up in the map - equality comparison can be done on the pointers of the reference counted values to resolve hash collisions.
Note that a
HashMap is internally implemented as a
HashSet of tuples where only the first half of the tuple is used for equality or hashing. I was imagining that we could write a wrapper struct with a custom
Hash impl such that this could be done with the