Compare commits

...

4 Commits

Author SHA1 Message Date
85f10be1d2 Merge pull request '1.3.3 release' (#8) from develop into main
All checks were successful
/ publish (push) Successful in 1m22s
Reviewed-on: Infendro/bytes-kt#8
2026-01-22 10:59:48 +00:00
345be1cc6f bump version to 1.3.3
All checks were successful
/ test (pull_request) Successful in 28s
2026-01-22 11:58:36 +01:00
d7d4e0c635 implement bytearray operators with byte 2026-01-22 11:35:09 +01:00
3e769fe4d0 small refactor to ci caching 2026-01-17 12:38:20 +01:00
5 changed files with 110 additions and 8 deletions

View File

@@ -19,7 +19,7 @@ jobs:
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
key: gradle-${{ hashFiles('**/libs.versions.toml') }} key: gradle-${{ hashFiles('**/libs.versions.toml') }}
restore-keys: gradle- restore-keys: gradle
path: | path: |
~/.gradle/caches/ ~/.gradle/caches/
~/.gradle/wrapper/ ~/.gradle/wrapper/
@@ -28,7 +28,7 @@ jobs:
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
key: konan-${{ hashFiles('**/libs.versions.toml') }} key: konan-${{ hashFiles('**/libs.versions.toml') }}
restore-keys: konan- restore-keys: konan
path: | path: |
~/.konan/ ~/.konan/
@@ -36,7 +36,7 @@ jobs:
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
key: node-${{ hashFiles('**/libs.versions.toml') }} key: node-${{ hashFiles('**/libs.versions.toml') }}
restore-keys: node- restore-keys: node
path: | path: |
~/.gradle/nodejs ~/.gradle/nodejs
~/.gradle/yarn ~/.gradle/yarn

View File

@@ -12,6 +12,6 @@ repositories {
} }
commonMain.dependencies { commonMain.dependencies {
implementation("com.infendro:bytes:1.3.2") implementation("com.infendro:bytes:1.3.3")
} }
``` ```

View File

@@ -5,7 +5,7 @@ import com.infendro.plugin.token
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
group = "com.infendro" group = "com.infendro"
version = "1.3.2" version = "1.3.3"
plugins { plugins {
alias(libs.plugins.infendro) alias(libs.plugins.infendro)

View File

@@ -25,15 +25,33 @@ private inline fun ByteArray.combineInto(
} }
} }
private inline fun ByteArray.combine( private inline fun ByteArray.combineInto(
that: ByteArray, that: Byte,
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
combine: (Byte, Byte) -> Byte, combine: (Byte, Byte) -> Byte,
): ByteArray { ) {
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] = combine(this[startIndex + i], that)
}
}
private inline fun ByteArray.combine(that: ByteArray, combine: (Byte, Byte) -> Byte): ByteArray {
require(this.size == that.size) require(this.size == that.size)
return ByteArray(size).also { combineInto(that, it, combine = combine) } 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) }
fun ByteArray.invInto( fun ByteArray.invInto(
destination: ByteArray, destination: ByteArray,
destinationOffset: Int = 0, destinationOffset: Int = 0,
@@ -62,9 +80,20 @@ fun ByteArray.andInto(
thatStartIndex: Int = 0, thatStartIndex: Int = 0,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex, thatStartIndex) { a, b -> a and b } ) = combineInto(that, destination, destinationOffset, startIndex, endIndex, thatStartIndex) { a, b -> a and b }
fun ByteArray.andInto(
that: Byte,
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex) { a, b -> a and b }
infix fun ByteArray.and(that: ByteArray): ByteArray = infix fun ByteArray.and(that: ByteArray): ByteArray =
combine(that) { a, b -> a and b } combine(that) { a, b -> a and b }
infix fun ByteArray.and(that: Byte): ByteArray =
combine(that) { a, b -> a and b }
fun ByteArray.orInto( fun ByteArray.orInto(
that: ByteArray, that: ByteArray,
destination: ByteArray, destination: ByteArray,
@@ -74,9 +103,20 @@ fun ByteArray.orInto(
thatStartIndex: Int = 0, thatStartIndex: Int = 0,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex, thatStartIndex) { a, b -> a or b } ) = combineInto(that, destination, destinationOffset, startIndex, endIndex, thatStartIndex) { a, b -> a or b }
fun ByteArray.orInto(
that: Byte,
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex) { a, b -> a or b }
infix fun ByteArray.or(that: ByteArray): ByteArray = infix fun ByteArray.or(that: ByteArray): ByteArray =
combine(that) { a, b -> a or b } combine(that) { a, b -> a or b }
infix fun ByteArray.or(that: Byte): ByteArray =
combine(that) { a, b -> a or b }
fun ByteArray.xorInto( fun ByteArray.xorInto(
that: ByteArray, that: ByteArray,
destination: ByteArray, destination: ByteArray,
@@ -86,5 +126,16 @@ fun ByteArray.xorInto(
thatStartIndex: Int = 0, thatStartIndex: Int = 0,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex, thatStartIndex) { a, b -> a xor b } ) = combineInto(that, destination, destinationOffset, startIndex, endIndex, thatStartIndex) { a, b -> a xor b }
fun ByteArray.xorInto(
that: Byte,
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex) { a, b -> a xor b }
infix fun ByteArray.xor(that: ByteArray): ByteArray = infix fun ByteArray.xor(that: ByteArray): ByteArray =
combine(that) { a, b -> a xor b } combine(that) { a, b -> a xor b }
infix fun ByteArray.xor(that: Byte): ByteArray =
combine(that) { a, b -> a xor b }

View File

@@ -31,9 +31,26 @@ fun UByteArray.andInto(
thatStartIndex, thatStartIndex,
) )
fun UByteArray.andInto(
that: UByte,
destination: UByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) = asByteArray().andInto(
that.toByte(),
destination.asByteArray(),
destinationOffset,
startIndex,
endIndex,
)
infix fun UByteArray.and(that: UByteArray): UByteArray = infix fun UByteArray.and(that: UByteArray): UByteArray =
UByteArray(size).also { andInto(that, it) } UByteArray(size).also { andInto(that, it) }
infix fun UByteArray.and(that: UByte): UByteArray =
UByteArray(size).also { andInto(that, it) }
fun UByteArray.orInto( fun UByteArray.orInto(
that: UByteArray, that: UByteArray,
destination: UByteArray, destination: UByteArray,
@@ -50,9 +67,26 @@ fun UByteArray.orInto(
thatStartIndex, thatStartIndex,
) )
fun UByteArray.orInto(
that: UByte,
destination: UByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) = asByteArray().orInto(
that.toByte(),
destination.asByteArray(),
destinationOffset,
startIndex,
endIndex,
)
infix fun UByteArray.or(that: UByteArray): UByteArray = infix fun UByteArray.or(that: UByteArray): UByteArray =
UByteArray(size).also { orInto(that, it) } UByteArray(size).also { orInto(that, it) }
infix fun UByteArray.or(that: UByte): UByteArray =
UByteArray(size).also { orInto(that, it) }
fun UByteArray.xorInto( fun UByteArray.xorInto(
that: UByteArray, that: UByteArray,
destination: UByteArray, destination: UByteArray,
@@ -69,5 +103,22 @@ fun UByteArray.xorInto(
thatStartIndex, thatStartIndex,
) )
fun UByteArray.xorInto(
that: UByte,
destination: UByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) = asByteArray().xorInto(
that.toByte(),
destination.asByteArray(),
destinationOffset,
startIndex,
endIndex,
)
infix fun UByteArray.xor(that: UByteArray): UByteArray = infix fun UByteArray.xor(that: UByteArray): UByteArray =
UByteArray(size).also { xorInto(that, it) } UByteArray(size).also { xorInto(that, it) }
infix fun UByteArray.xor(that: UByte): UByteArray =
UByteArray(size).also { xorInto(that, it) }