There used to be an IdentityHashMap
in collection.jcl
: is there a way of constructing the same thing in the new 2.8 collections library (perhaps with a bespoke equality-relation)?
views:
88answers:
1
+4
A:
In scala.collection.mutable.HashMap
there are two protected methods, elemEquals
and elemHashCode
. If you override them you can create an IdentityHashMap
of your own.
In scala.collection.immutable.HashMap
there is only elemHashCode
. (I don't know why, offhand.)
Randall Schulz
2010-07-21 15:48:41
This wouldn't work for immutable maps because a new one is created every time an addition is made. So you'd have to modify the updated/remove logic as well, which could quickly get messy
oxbow_lakes
2010-07-25 10:54:25
Yes, that makes sense. Thanks.
Randall Schulz
2010-07-25 14:23:05