Changing default / load factor scala mutable.HashMap

I am currently using scala 2.9.1. I create mutable.HashMap using:

> val m = mutable.HashMap.empty[Int, Int] 

I am new to scala. In java, I was able to specify the capacity and load factor in the HashMap constructor. I cannot find a way to do the same in scala.

Thanks at Advance

+7
source share
1 answer

According to the API, this is not possible. One explanation is that volatile collections are very discouraged, and immutable collections do not need default capacity information, since the number of elements must be known at build time.

However, note that Scala will implicitly use the default capacity information if you create a collection (including mutable and immutable HashMap ) using the many collection methods available. For example, if you call map on a HashMap , it will use the map defined in the TraversableLike (reproduced below), and you can see that it provides a โ€œsize hintโ€ to the builder, which provides this information capacity.

 def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) b.sizeHint(this) for (x <- this) b += f(x) b.result } 
+4
source

All Articles