Accept in-projection of Comparator as a parameter when possible.

This commit is contained in:
Ilya Gorbunov
2015-09-07 21:27:50 +03:00
parent 37d5a16a3d
commit 52f3e9ca06
5 changed files with 5 additions and 5 deletions
@@ -140,7 +140,7 @@ public fun ShortArray.asList(): List<Short> {
/**
* Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted according to the specified [comparator].
*/
public fun <T> Array<out T>.binarySearch(element: T, comparator: Comparator<T>, fromIndex: Int = 0, toIndex: Int = size()): Int {
public fun <T> Array<out T>.binarySearch(element: T, comparator: Comparator<in T>, fromIndex: Int = 0, toIndex: Int = size()): Int {
return Arrays.binarySearch(this, fromIndex, toIndex, element, comparator)
}
@@ -190,7 +190,7 @@ public fun <T: Comparable<T>> List<T?>.binarySearch(element: T?, fromIndex: Int
*
* If the list contains multiple elements equal to the specified object, there is no guarantee which one will be found.
*/
public fun <T> List<T>.binarySearch(element: T, comparator: Comparator<T>, fromIndex: Int = 0, toIndex: Int = size()): Int {
public fun <T> List<T>.binarySearch(element: T, comparator: Comparator<in T>, fromIndex: Int = 0, toIndex: Int = size()): Int {
rangeCheck(size(), fromIndex, toIndex)
var low = fromIndex
@@ -29,7 +29,7 @@ public fun sortedSetOf<T>(vararg values: T): TreeSet<T> = values.toCollection(Tr
/**
* Returns a new [SortedSet] with the given [comparator] and elements.
*/
public fun sortedSetOf<T>(comparator: Comparator<T>, vararg values: T): TreeSet<T> = values.toCollection(TreeSet<T>(comparator))
public fun sortedSetOf<T>(comparator: Comparator<in T>, vararg values: T): TreeSet<T> = values.toCollection(TreeSet<T>(comparator))
/**
* Returns a list containing the elements returned by this enumeration
@@ -50,7 +50,7 @@ public fun <K : Comparable<K>, V> Map<K, V>.toSortedMap(): SortedMap<K, V> = Tre
*
* @sample test.collections.MapJVMTest.toSortedMapWithComparator
*/
public fun <K, V> Map<K, V>.toSortedMap(comparator: Comparator<K>): SortedMap<K, V> {
public fun <K, V> Map<K, V>.toSortedMap(comparator: Comparator<in K>): SortedMap<K, V> {
val result = TreeMap<K, V>(comparator)
result.putAll(this)
return result
@@ -108,7 +108,7 @@ fun specialJVM(): List<GenericFunction> {
}
}
templates add f("binarySearch(element: T, comparator: Comparator<T>, fromIndex: Int = 0, toIndex: Int = size())") {
templates add f("binarySearch(element: T, comparator: Comparator<in T>, fromIndex: Int = 0, toIndex: Int = size())") {
only(ArraysOfObjects)
doc { "Searches array or range of array for provided element index using binary search algorithm. Array is expected to be sorted according to the specified [comparator]." }
returns("Int")