diff --git a/util-core/src/main/scala-2.12-/com/twitter/util/MapUtil.scala b/util-core/src/main/scala-2.12-/com/twitter/util/MapUtil.scala new file mode 100644 index 0000000000..6e180c84be --- /dev/null +++ b/util-core/src/main/scala-2.12-/com/twitter/util/MapUtil.scala @@ -0,0 +1,13 @@ +package com.twitter.util + +import scala.collection.mutable + +object MapUtil { + + def newHashMap[K, V](initialCapacity: Int, loadFactor: Double = 0.75): mutable.HashMap[K, V] = { + new mutable.HashMap[K, V]() { + this._loadFactor = (loadFactor * 1000).toInt + override protected val initialSize: Int = (size.toLong / loadFactor).toInt + } + } +} diff --git a/util-core/src/main/scala-2.13+/com/twitter/util/MapUtil.scala b/util-core/src/main/scala-2.13+/com/twitter/util/MapUtil.scala new file mode 100644 index 0000000000..2994ca876c --- /dev/null +++ b/util-core/src/main/scala-2.13+/com/twitter/util/MapUtil.scala @@ -0,0 +1,10 @@ +package com.twitter.util + +import scala.collection.mutable + +object MapUtil { + + def newHashMap[K, V](initialCapacity: Int, loadFactor: Double = 0.75): mutable.HashMap[K, V] = { + new mutable.HashMap[K, V](initialCapacity, loadFactor) + } +}