-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRolling hash.cpp
More file actions
39 lines (31 loc) · 839 Bytes
/
Rolling hash.cpp
File metadata and controls
39 lines (31 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* A small rolling hash snippet. Work is in progress.*/
const int HASH_SIZE=2;
const long long BASE=27;
long long mods[4]={1000000007,998244353,900000001553,1000000007};
long long bases[4]={27,40,55,110};
typedef struct rollhash{
long long hashval[HASH_SIZE];
rollhash(){
for(int i=0;i<HASH_SIZE;i++){
hashval[i]=0;
}
}
};
bool operator < (rollhash le,rollhash ri){
if(le.hashval[0]==ri.hashval[0]){
return le.hashval[1]<ri.hashval[1];
}
return le.hashval[0]<ri.hashval[0];
}
rollhash mul_hash(rollhash &pre,long long val){
rollhash neww;
for(int i=0;i<HASH_SIZE;i++){
neww.hashval[i]=(((pre.hashval[i]*bases[i])%mods[i])+val)%mods[i];
}
return neww;
}
void init(rollhash &cur){
for(int i=0;i<HASH_SIZE;i++){
cur.hashval[i]=0;
}
}