Search optimisation
Posted: 04 May 2021, 20:58
Hello
I am trying to search a 7MB binary file for a few byte patterns, similar to using a search function in a typical hex editor program.
I am able to implement this in AHK with a naive search algorithm ('linear search') in conjunction with FileRead *C and NumGet UChar.
Being linear search it is obviously quite slow though.
For example, a typical hex editor can find all occurrences of a 24 byte pattern in a 7MB binary in just a fraction of a second -- they are obviously not using linear search and iterating through each byte like my AHK implementation.
Therefore, I am interested in implementing a smarter search algorithm in AHK.
Questions:
1. Which algorithm should I try to implement in AHK? Should I sort the data first and then use something like binary search / divide and conquer / hash tables? Wouldn't it take a very long time to sort the binary data? Hex editors can open and search files immediately, so I'm not sure they are sorting the binary data first.
2. Is there already a third party AHK implementation available?
3. Are there Windows API functions that implement various search algorithms on unsorted data?
Thanks
I am trying to search a 7MB binary file for a few byte patterns, similar to using a search function in a typical hex editor program.
I am able to implement this in AHK with a naive search algorithm ('linear search') in conjunction with FileRead *C and NumGet UChar.
Being linear search it is obviously quite slow though.
For example, a typical hex editor can find all occurrences of a 24 byte pattern in a 7MB binary in just a fraction of a second -- they are obviously not using linear search and iterating through each byte like my AHK implementation.
Therefore, I am interested in implementing a smarter search algorithm in AHK.
Questions:
1. Which algorithm should I try to implement in AHK? Should I sort the data first and then use something like binary search / divide and conquer / hash tables? Wouldn't it take a very long time to sort the binary data? Hex editors can open and search files immediately, so I'm not sure they are sorting the binary data first.
2. Is there already a third party AHK implementation available?
3. Are there Windows API functions that implement various search algorithms on unsorted data?
Thanks