scoop:scoop.std:0.1.0
src/collections/sorted_map_factories.scoop
Selected production source · src/collections/sorted_map_factories.scoop
1
package scoop.collections3
import scoop.comparisons.Comparator4
import scoop.comparisons.naturalOrder6
internal class SortedMapSnapshot<K, V> internal constructor(7
private val elements: SortedMap<K, V>8
) : SortedMap<K, V> by elements10
/**11
* Creates an ordered map using the supplied or natural comparator; comparator-equivalent keys12
* share one entry.13
*/14
public fun <K, V> sortedMapOf(comparator: Comparator<K>, vararg entries: (K, V)): TreeMap<K, V> {15
val result = TreeMap<K, V>(comparator)16
for ((key, value) in entries) result.put(key, value)17
return result18
}20
/**21
* Creates an ordered map using the supplied or natural comparator; comparator-equivalent keys22
* share one entry.23
*/24
public fun <K : Compare<K>, V> sortedMapOf(vararg entries: (K, V)): TreeMap<K, V> =25
sortedMapOf<K, V>(naturalOrder<K>(), *entries)27
/**28
* Copies associations into a read-only ordered map using the selected ordering.29
*/30
public fun <K, V> Iterable<(K, V)>.toSortedMap(comparator: Comparator<K>): SortedMap<K, V> {31
val result = TreeMap<K, V>(comparator)32
for ((key, value) in this) result.put(key, value)33
return SortedMapSnapshot<K, V>(result)34
}36
/**37
* Copies associations into a read-only ordered map using the selected ordering.38
*/39
public fun <K : Compare<K>, V> Iterable<(K, V)>.toSortedMap(): SortedMap<K, V> =40
toSortedMap<K, V>(naturalOrder<K>())42
/**43
* Copies associations into a read-only ordered map using the selected ordering.44
*/45
public fun <K, V> Map<K, V>.toSortedMap(comparator: Comparator<K>): SortedMap<K, V> {46
val result = TreeMap<K, V>(comparator)47
for ((key, value) in this) result.put(key, value)48
return SortedMapSnapshot<K, V>(result)49
}51
/**52
* Copies associations into a read-only ordered map using the selected ordering.53
*/54
public fun <K : Compare<K>, V> Map<K, V>.toSortedMap(): SortedMap<K, V> =55
toSortedMap<K, V>(naturalOrder<K>())