diff --git a/README.md b/README.md index c209931..b0bf649 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,6 @@ repositories { } commonMain.dependencies { - implementation("com.infendro:bytes:1.3.3") + implementation("com.infendro:bytes:1.3.4") } ``` diff --git a/build.gradle.kts b/build.gradle.kts index abb3c35..f0b339d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ import com.infendro.plugin.token import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl group = "com.infendro" -version = "1.3.3" +version = "1.3.4" plugins { alias(libs.plugins.infendro) diff --git a/src/commonMain/kotlin/com/infendro/bytes/bytearray/Operators.kt b/src/commonMain/kotlin/com/infendro/bytes/bytearray/Operators.kt index b597223..78c34c4 100644 --- a/src/commonMain/kotlin/com/infendro/bytes/bytearray/Operators.kt +++ b/src/commonMain/kotlin/com/infendro/bytes/bytearray/Operators.kt @@ -49,15 +49,11 @@ private inline fun ByteArray.combine(that: ByteArray, combine: (Byte, Byte) -> B return ByteArray(size).also { combineInto(that, it, combine = combine) } } -private inline fun ByteArray.combine(that: Byte, combine: (Byte, Byte) -> Byte): ByteArray = - ByteArray(size).also { combineInto(that, it, combine = combine) } +private inline fun ByteArray.combine(that: Byte, combine: (Byte, Byte) -> Byte): ByteArray { + return ByteArray(size).also { combineInto(that, it, combine = combine) } +} -fun ByteArray.invInto( - destination: ByteArray, - destinationOffset: Int = 0, - startIndex: Int = 0, - endIndex: Int = size, -) { +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)) @@ -68,6 +64,9 @@ fun ByteArray.invInto( } } +fun ByteArray.invInto(startIndex: Int = 0, endIndex: Int = size) = + invInto(this, startIndex, startIndex, endIndex) + fun ByteArray.inv(): ByteArray = ByteArray(size).also { invInto(it) } @@ -88,6 +87,16 @@ fun ByteArray.andInto( endIndex: Int = size, ) = combineInto(that, destination, destinationOffset, startIndex, endIndex) { a, b -> a and b } +fun ByteArray.andInto(destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) = + combineInto( + destination, + destination, + destinationOffset, + startIndex, + endIndex, + destinationOffset, + ) { a, b -> a and b } + infix fun ByteArray.and(that: ByteArray): ByteArray = combine(that) { a, b -> a and b } @@ -111,6 +120,16 @@ fun ByteArray.orInto( endIndex: Int = size, ) = combineInto(that, destination, destinationOffset, startIndex, endIndex) { a, b -> a or b } +fun ByteArray.orInto(destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) = + combineInto( + destination, + destination, + destinationOffset, + startIndex, + endIndex, + destinationOffset, + ) { a, b -> a or b } + infix fun ByteArray.or(that: ByteArray): ByteArray = combine(that) { a, b -> a or b } @@ -134,6 +153,16 @@ fun ByteArray.xorInto( endIndex: Int = size, ) = combineInto(that, destination, destinationOffset, startIndex, endIndex) { a, b -> a xor b } +fun ByteArray.xorInto(destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) = + combineInto( + destination, + destination, + destinationOffset, + startIndex, + endIndex, + destinationOffset, + ) { a, b -> a xor b } + infix fun ByteArray.xor(that: ByteArray): ByteArray = combine(that) { a, b -> a xor b } diff --git a/src/commonMain/kotlin/com/infendro/bytes/ubytearray/Operators.kt b/src/commonMain/kotlin/com/infendro/bytes/ubytearray/Operators.kt index d64372c..706976e 100644 --- a/src/commonMain/kotlin/com/infendro/bytes/ubytearray/Operators.kt +++ b/src/commonMain/kotlin/com/infendro/bytes/ubytearray/Operators.kt @@ -5,12 +5,11 @@ import com.infendro.bytes.bytearray.invInto import com.infendro.bytes.bytearray.orInto import com.infendro.bytes.bytearray.xorInto -fun UByteArray.invInto( - destination: UByteArray, - destinationOffset: Int = 0, - startIndex: Int = 0, - endIndex: Int = size, -) = asByteArray().invInto(destination.asByteArray(), destinationOffset, startIndex, endIndex) +fun UByteArray.invInto(destination: UByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) = + asByteArray().invInto(destination.asByteArray(), destinationOffset, startIndex, endIndex) + +fun UByteArray.invInto(startIndex: Int = 0, endIndex: Int = size) = + asByteArray().invInto(asByteArray(), startIndex, startIndex, endIndex) fun UByteArray.inv(): UByteArray = UByteArray(size).also { invInto(it) } @@ -45,6 +44,16 @@ fun UByteArray.andInto( endIndex, ) +fun UByteArray.andInto(destination: UByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) = + asByteArray().andInto( + destination.asByteArray(), + destination.asByteArray(), + destinationOffset, + startIndex, + endIndex, + destinationOffset, + ) + infix fun UByteArray.and(that: UByteArray): UByteArray = UByteArray(size).also { andInto(that, it) } @@ -81,6 +90,16 @@ fun UByteArray.orInto( endIndex, ) +fun UByteArray.orInto(destination: UByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) = + asByteArray().orInto( + destination.asByteArray(), + destination.asByteArray(), + destinationOffset, + startIndex, + endIndex, + destinationOffset, + ) + infix fun UByteArray.or(that: UByteArray): UByteArray = UByteArray(size).also { orInto(that, it) } @@ -117,6 +136,16 @@ fun UByteArray.xorInto( endIndex, ) +fun UByteArray.xorInto(destination: UByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) = + asByteArray().xorInto( + destination.asByteArray(), + destination.asByteArray(), + destinationOffset, + startIndex, + endIndex, + destinationOffset, + ) + infix fun UByteArray.xor(that: UByteArray): UByteArray = UByteArray(size).also { xorInto(that, it) }