Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala map with primitive types value type

Tags:

scala

As I understand, declaring a map from scala stdlib doesn't specialize it to primitive types. What I'm looking for is not to pay the price of boxing/unboxing, but at the same time have the interface of scala maps. An obvious choice would be to use trove maps, but I don't believe there are scala views. Any help appreciated.

like image 891
venechka Avatar asked Oct 11 '22 07:10

venechka


1 Answers

This is currently impossible because the interface is not specialized. This means that regardless of what you do in the collection itself, the values will be boxed in order to get them through the interface.

There are no particularly satisfying options at the moment; using Trove with some implicit conversions to Scala collections for those cases where convenience is more important than performance is probably the best you'll get.

(I have tried to remedy this situation myself, and can attest that it is not easy given the current state of specialization support in the compiler; specializing the existing library isn't practical right now, and creating your own is difficult at best. Hopefully future versions will improve things here, but this isn't of much use to you right now.)

like image 115
Rex Kerr Avatar answered Oct 28 '22 10:10

Rex Kerr