A "mappable" type would have a Hash() method.
Therefore, a given oject, say : k satisfying said "mappable"
interface, would be represented internally (in the map) as k.Hash(),
in other words as an interger.
Since the existing map container works for integers, it would work
for k.Hash(), hence for k.
In the case of int, resp. strings, Hash() would just be the indentity
function.
On the other hand, as far as performance is concerned, I think that in
most cases there would be no difference between:
1. Providing a generalized map working on the "mappable" interface.
2. Storing arbitrary objects via serialization.
(since providing a Hash() method or a serailization function would be
very similar in cases like structs, for instance).
For example : I think there would not be any performance gain, in
storing a struct which holds strings, between :
a. providing a function rediucing the struct to a string (and vice
versa)
b. providing a Hash() method acting on that type of struct
basically because solution b. would use solution a. (in this example)
Serge.
Serge.
On Jul 14, 2:52 am, David Roundy <
roun...@physics.oregonstate.edu>
wrote:
> How do you handle the case where the key changes? If you can assume
> there are no hash collisions, this isn't an issue, since you can just
> use the value when a given element was added, but if you aren't
> willing to make that assumption, then you need to add an extra copy
> when adding something to the hash, which doesn't seem very nice. For
> small types, it would be fine, but for larger types, it seems like
> this could be a nasty performance pitfall...
>
> David
>