add return types

This commit is contained in:
2026-01-15 14:56:46 +01:00
parent d55ec62be9
commit dddf2bab93
10 changed files with 42 additions and 42 deletions

View File

@@ -5,25 +5,6 @@ import kotlin.experimental.inv
import kotlin.experimental.or
import kotlin.experimental.xor
fun ByteArray.invInto(
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) {
val length = endIndex - startIndex
require(length >= 0)
require(startIndex in 0..(size - length))
require(destinationOffset in 0..(destination.size - length))
repeat(length) { i ->
destination[destinationOffset + i] = this[startIndex + i].inv()
}
}
fun ByteArray.inv() =
ByteArray(size).also { invInto(it) }
private inline fun ByteArray.combineInto(
that: ByteArray,
destination: ByteArray,
@@ -53,6 +34,25 @@ private inline fun ByteArray.combine(
return ByteArray(size).also { combineInto(that, it, combine = combine) }
}
fun ByteArray.invInto(
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) {
val length = endIndex - startIndex
require(length >= 0)
require(startIndex in 0..(size - length))
require(destinationOffset in 0..(destination.size - length))
repeat(length) { i ->
destination[destinationOffset + i] = this[startIndex + i].inv()
}
}
fun ByteArray.inv(): ByteArray =
ByteArray(size).also { invInto(it) }
fun ByteArray.andInto(
that: ByteArray,
destination: ByteArray,
@@ -62,7 +62,7 @@ fun ByteArray.andInto(
thatStartIndex: Int = 0,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex, thatStartIndex) { a, b -> a and b }
infix fun ByteArray.and(that: ByteArray) =
infix fun ByteArray.and(that: ByteArray): ByteArray =
combine(that) { a, b -> a and b }
fun ByteArray.orInto(
@@ -74,7 +74,7 @@ fun ByteArray.orInto(
thatStartIndex: Int = 0,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex, thatStartIndex) { a, b -> a or b }
infix fun ByteArray.or(that: ByteArray) =
infix fun ByteArray.or(that: ByteArray): ByteArray =
combine(that) { a, b -> a or b }
fun ByteArray.xorInto(
@@ -86,5 +86,5 @@ fun ByteArray.xorInto(
thatStartIndex: Int = 0,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex, thatStartIndex) { a, b -> a xor b }
infix fun ByteArray.xor(that: ByteArray) =
infix fun ByteArray.xor(that: ByteArray): ByteArray =
combine(that) { a, b -> a xor b }