Introduce overloads to check for T? element contained in iterable range in a constant time

#KT-18483
This commit is contained in:
Ilya Gorbunov
2018-09-10 04:18:14 +03:00
parent 64e85e8a0c
commit 1eda3805ec
5 changed files with 102 additions and 0 deletions
@@ -93,6 +93,39 @@ public fun CharRange.random(random: Random): Char {
}
}
/**
* Returns `true` if this range contains the specified [element].
*
* Always returns `false` if the [element] is `null`.
*/
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
public inline operator fun IntRange.contains(element: Int?): Boolean {
return element != null && contains(element)
}
/**
* Returns `true` if this range contains the specified [element].
*
* Always returns `false` if the [element] is `null`.
*/
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
public inline operator fun LongRange.contains(element: Long?): Boolean {
return element != null && contains(element)
}
/**
* Returns `true` if this range contains the specified [element].
*
* Always returns `false` if the [element] is `null`.
*/
@SinceKotlin("1.3")
@kotlin.internal.InlineOnly
public inline operator fun CharRange.contains(element: Char?): Boolean {
return element != null && contains(element)
}
/**
* Checks if the specified [value] belongs to this range.
*/
@@ -72,6 +72,30 @@ public fun ULongRange.random(random: Random): ULong {
}
}
/**
* Returns `true` if this range contains the specified [element].
*
* Always returns `false` if the [element] is `null`.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline operator fun UIntRange.contains(element: UInt?): Boolean {
return element != null && contains(element)
}
/**
* Returns `true` if this range contains the specified [element].
*
* Always returns `false` if the [element] is `null`.
*/
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
@kotlin.internal.InlineOnly
public inline operator fun ULongRange.contains(element: ULong?): Boolean {
return element != null && contains(element)
}
/**
* Returns a progression from this value down to the specified [to] value with the step -1.
*