com.soywiz.kmem.ByteArrayUtils.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kmem-common Show documentation
Show all versions of kmem-common Show documentation
kmem: Fast memory for Kotlin Common (JVM and JS) using Buffers and Typed Arrays
The newest version!
package com.soywiz.kmem
fun ByteArray.contains(other: ByteArray): Boolean = indexOf(other) >= 0
fun ByteArray.indexOf(other: ByteArray): Int {
val full = this
for (n in 0 until full.size - other.size) {
if (other.indices.all { m -> full[n + m] == other[m] }) {
return n
}
}
return -1
}