Hi, I'm looking for an elegant way to find a sequence of bytes in a byte array, e.g. find the sequence [0xFF] [0xFF] [0xFF] [0xFF]. Can someone help me?
v
Vampire
01/07/2021, 4:37 PM
Maybe windowed with a window size of 4 and then searching for your 4 byte sequence in the windows?
☝️ 2
l
Lilly
01/07/2021, 5:02 PM
@Vampire Can you give me some pseudo code?
Edit: I'm fine. Was wondering how to compare the byte arrays, but found
contentEquals
Thanks for the fast reply
v
Vampire
01/07/2021, 5:10 PM
yw
e
ephemient
01/07/2021, 7:03 PM
a substring matching algorithm like Knuth-Morris-Pratt or Aho-Corasick can be more efficient
👍 1
ephemient
01/07/2021, 7:05 PM
I don't know if any existing implementations for Kotlin on ByteArray but if you're literally searching for [0xFF x 4] a tiny inline automaton is easy