Remove dependency of "descriptors" on Maps/Sets

This commit is contained in:
Alexander Udalov
2014-08-14 15:50:05 +04:00
parent 9bc7d27fe1
commit 2055d4d72c
19 changed files with 76 additions and 97 deletions
@@ -18,6 +18,8 @@ package org.jetbrains.jet.utils
import java.util.LinkedHashMap
import java.util.ArrayList
import java.util.HashMap
import java.util.HashSet
public fun <K, V> Stream<V>.valuesToMap(key: (V) -> K): Map<K, V> {
val map = LinkedHashMap<K, V>()
@@ -83,4 +85,12 @@ public fun <T: Any> emptyOrSingletonList(item: T?): List<T> = if (item == null)
public fun <T: Any> MutableCollection<T>.addIfNotNull(t: T?) {
if (t != null) add(t)
}
}
public fun <K, V> newHashMapWithExpectedSize(expectedSize: Int): HashMap<K, V> {
return HashMap(if (expectedSize < 3) 3 else expectedSize + expectedSize / 3 + 1)
}
public fun <E> newHashSetWithExpectedSize(expectedSize: Int): HashSet<E> {
return HashSet(if (expectedSize < 3) 3 else expectedSize + expectedSize / 3 + 1)
}