Tuesday, 17 September 2013

Scala - hashCode caching for immutable collections

Scala - hashCode caching for immutable collections

It seems that immutable scala collections do not cache their hashCode
calculations (tested for immutable.HashSet), but instead re-compute it
each time. Is there any easy way to add this behaviour (for performance
reasons)?
I've thought about creating a subclass of immutable.HashSet which does the
caching, but didn't see any way to implement the + etc. functions to
return an caching object. While possible to do with delegation, that's
just seems horribly ugly.

No comments:

Post a Comment