Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- unsigned const int W = 997;
- unsigned const int S = 128; //ascci value that we are used in our test!
- unsigned int hash(char *s, int len){
- unsigned h=0;
- for(int k=0; k<len;k++)
- h=(h*S + s[k])%W;
- return h;
- }
- unsigned int rehash(unsigned int spower, char oldc, char inewc, unsigned int oldhash){
- return (((oldhash - oldc * spower)* S + inewc) % W+W)%W;
- }
- int main()
- {
- cout << hash("Cona",4) << endl;
- cout << rehash(3,'n','m',5) << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment