fix global scope pollution
This commit is contained in:
parent
57e4819430
commit
e41bbe711c
@ -13,15 +13,23 @@ import space.kscience.kmath.structures.*
|
||||
*/
|
||||
public class ExtremeValueStatistic<T>(
|
||||
private val comparator: Comparator<T>,
|
||||
): ComposableStatistic<T, T, T>, BlockingStatistic<T, T> {
|
||||
) : ComposableStatistic<T, T, T>, BlockingStatistic<T, T> {
|
||||
|
||||
public companion object {
|
||||
public fun <T> maxStatistic(): ExtremeValueStatistic<T> where T : Comparable<T> =
|
||||
ExtremeValueStatistic(reverseOrder())
|
||||
|
||||
public fun <T> minStatistic(): ExtremeValueStatistic<T> where T : Comparable<T> =
|
||||
ExtremeValueStatistic(naturalOrder())
|
||||
}
|
||||
|
||||
override fun evaluateBlocking(data: Buffer<T>): T {
|
||||
require(data.size > 0) { "Data must not be empty" }
|
||||
var res = data[0]
|
||||
for (i in data.indices) {
|
||||
if (comparator.compare(data[i], res) < 0) {
|
||||
res = data[i]
|
||||
}
|
||||
if (comparator.compare(data[i], res) < 0) {
|
||||
res = data[i]
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
@ -31,7 +39,7 @@ public class ExtremeValueStatistic<T>(
|
||||
override suspend fun composeIntermediate(first: T, second: T): T {
|
||||
if (comparator.compare(first, second) < 0) {
|
||||
return first
|
||||
} else{
|
||||
} else {
|
||||
return second
|
||||
}
|
||||
}
|
||||
@ -42,19 +50,12 @@ public class ExtremeValueStatistic<T>(
|
||||
|
||||
}
|
||||
|
||||
|
||||
public fun <T> minStatistic(): ExtremeValueStatistic<T> where T : Comparable<T> =
|
||||
ExtremeValueStatistic(naturalOrder())
|
||||
|
||||
public fun <T> maxStatistic(): ExtremeValueStatistic<T> where T : Comparable<T> =
|
||||
ExtremeValueStatistic(reverseOrder())
|
||||
|
||||
// min
|
||||
public val Float64Field.min: ExtremeValueStatistic<Float64> get() = minStatistic()
|
||||
public val Int32Ring.min: ExtremeValueStatistic<Int32> get() = minStatistic()
|
||||
public val Int64Ring.min: ExtremeValueStatistic<Int64> get() = minStatistic()
|
||||
public val Float64Field.min: ExtremeValueStatistic<Float64> get() = ExtremeValueStatistic.minStatistic()
|
||||
public val Int32Ring.min: ExtremeValueStatistic<Int32> get() = ExtremeValueStatistic.minStatistic()
|
||||
public val Int64Ring.min: ExtremeValueStatistic<Int64> get() = ExtremeValueStatistic.minStatistic()
|
||||
|
||||
// max
|
||||
public val Float64Field.max: ExtremeValueStatistic<Float64> get() = maxStatistic()
|
||||
public val Int32Ring.max: ExtremeValueStatistic<Int32> get() = maxStatistic()
|
||||
public val Int64Ring.max: ExtremeValueStatistic<Int64> get() = maxStatistic()
|
||||
public val Float64Field.max: ExtremeValueStatistic<Float64> get() = ExtremeValueStatistic.maxStatistic()
|
||||
public val Int32Ring.max: ExtremeValueStatistic<Int32> get() = ExtremeValueStatistic.maxStatistic()
|
||||
public val Int64Ring.max: ExtremeValueStatistic<Int64> get() = ExtremeValueStatistic.maxStatistic()
|
Loading…
x
Reference in New Issue
Block a user