5 #ifndef DSALGLIB_KMPSEARCH_H 6 #define DSALGLIB_KMPSEARCH_H 12 template<
typename type>
15 long long int pindex =0;
16 for(
long long int cindex=1; cindex < pat.
size();)
18 if(pat[cindex] == pat[pindex]){
19 pre[cindex] = pindex + 1;
24 pindex = pre[pindex-1];
33 template<
typename type>
39 long long int aindex=0,pindex=0;
40 while(aindex<arr.
size())
42 if(arr[aindex]==pat[pindex]){
46 if(pindex==pat.
size()){
47 res.push_back(aindex-pindex);
49 }
else if(aindex<arr.
size() && arr[aindex]!=pat[pindex]){
50 if(pindex!=0) pindex= pre[pindex-1];
else aindex++;
56 #endif //DSALGLIB_KMPSEARCH_H
array< long long int > kmpsearch(array< type > arr, array< type > pat)
void kmppreprocess(array< long long int > pre, array< type > pat)