Debian Codegraph @

jmh-scala-tests/src/main/scala/org/eclipse/collections/impl/jmh/map/PresizableHashMap.scala

raw
1 /*
2 * Copyright (c) 2021 Goldman Sachs.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and Eclipse Distribution License v. 1.0 which accompany this distribution.
6 * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
7 * and the Eclipse Distribution License is available at
8 * http://www.eclipse.org/org/documents/edl-v10.php.
9 */
10
11 package org.eclipse.collections.impl.jmh.map
12
13 class PresizableHashMap[K, V](val _initialSize: Int) extends scala.collection.mutable.HashMap[K, V]
14 {
15 private def initialCapacity =
16 if (_initialSize == 0) 1
17 else smallestPowerOfTwoGreaterThan((_initialSize.toLong * 1000 / _loadFactor).asInstanceOf[Int])
18
19 private def smallestPowerOfTwoGreaterThan(n: Int): Int =
20 if (n > 1) Integer.highestOneBit(n - 1) << 1 else 1
21
22 table = new Array(initialCapacity)
23 threshold = ((initialCapacity.toLong * _loadFactor) / 1000).toInt
24 }