-3

I come up an idea to read a byte[] array with the same size of the input, and check one by one. But it seems not very efficient. Is there a way to solve it by using rolling hash?

4
  • do i get you right, you have an byte-array X and you have a file and you want to check if X is somewhere in the file data? Commented Nov 24, 2017 at 23:18
  • 1
    Show some code and then ask a specific question Commented Nov 24, 2017 at 23:19
  • Please see: stackoverflow.com/questions/1507780/… Commented Nov 24, 2017 at 23:20
  • You can compute a rolling hash (Rabin Karp or some other ) , over a sliding window of size as byte array, over the entire file and check whether hash is the same. If same , then compare byte by byte. Since computing rolling hash is O(1), you will be able to solve the problem in O(file_size) . Commented Feb 20, 2018 at 3:39

1 Answer 1

0

If you are using java 8 or above please check the

java.util.Optional<T>

The documentation is here Optional If I got what you mean correctly

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.