which piece of data do you want in your hash table?
I don't know the RK algorithm you show but it should just be to figure out what piece(s) of data you want stored and fetched and putting those in your object.
function RabinKarp(string s[1..n], string pattern[1..m])
hpattern := hash(pattern[1..m]);
for i from 1 to n-m+1
hs := hash(s[i..i+m-1])
if hs = hpattern
if s[i..i+m-1] = pattern[1..m]
return i
return not found
I need to find is there a String P ( pattern ) in string T (text). So I need to search for P in T. All that I want to do by using that hash.h.
your class is a hash-table, a container.
that algorithm sure looks to me like a hash value-generator, like SHA*, (not a container).
Can you review these 2 ideas and tell me if that is the problem?
you don't need a heavy hash function if its for values. you can do a quick crc type; it looks like you need what is called a rolling-hash (I gave in and looked it up) which can be done with crcs.
A rolling hash (also known as recursive hashing or rolling checksum) is a hash function where the input is hashed in a window that moves through the input. https://en.wikipedia.org/wiki/Rolling_hash
a string-searching algorithm created by Richard M. Karp and Michael O. Rabin (1987) that uses hashing to find an exact match of a pattern string in a text. It uses a rolling hash to quickly filter out positions of the text that cannot match the pattern https://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm
I have done this problem using rolling hash function and that all works just fine, but now I also have to do it with this exact hash function I have written in hash.h. At the end I came to this point where I do not know what to do next, how to make it working and how to put it all together.
you need to take the hash function and isolate it to just return the index/ result number then, and call that without using the container parts of the class, or just make a stand-alone function out of the class that runs that small piece of it.
What do you mean by isolating just to return index? Do I need to make function that just returns keys or number of elements? What I am going to do with rest of class, can I dismiss it ? Is that (the only ) function I need to call later in code for (RK) algorithm (instead int h1 = Hash(n);] I call that new function that is in header )?
Hash(n) ... I don't see this, but the mismatched {}s and indentation in the forum is not helping me spot it.
If that returns what you want, then use it exactly the same way you used it in the one that worked with your rolling hash function.