private long recalculateHash(char[] str,int oldIndex, int newIndex,long oldHash, int patternLen) {
        long newHash = oldHash - str[oldIndex];
        newHash = newHash/prime;
        newHash += str[newIndex]*Math.pow(prime, patternLen - 1);
        return newHash;
    }
Date 09/25/2014
@author Tushar Roy

Rabin Karp algorith for substring matching.

Time complexity in worst case O(n^2)(depends on hash function)
Space complexity O(1)

References
https://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm
src/com/interview/string/RabinKarpSearch.java