#include #include #include #include #include #include // for memcpy #include // for not_equal_to #include #include using std::vector; template < typename T, class Seq , class NotEq > void NaiveMatcher (Seq &data, Seq &pat, bool *tr , int n,int m) { NotEq neq; // int r=n-m; int s=0; typename Seq::iterator pIt; typename Seq::iterator endIt=pat.end(); typename Seq::iterator dIt; typename Seq::iterator dEnd; typename Seq::iterator pBeg=pat.begin(); typename Seq::iterator dBeg=data.begin(); do { dIt=dBeg+s; dEnd=dIt+m; pIt=pBeg; while (pIt!=endIt) { if ( neq(*pIt,*dIt) ) { tr[s]=false; break; } pIt++; dIt++; } s++; } while (dEnd!=data.end()); } template < typename T, class NotEq > void NaiveMatcher2 (T* data, T* pat, bool *tr , int n,int m) { NotEq neq; int r=n-m; for (int s=0;s(pow(o,m-1)) % q; int pt=0; int t0=0; int r=n-m; for (int i=0;i=r) { printf("Invalid data\n"); return -1; } int *T=new int[n], *P=new int[m]; bool *TR=new bool[r]; srand(time(NULL)); for (int i=0;i (static_cast (d) * ( rand() / (RAND_MAX + 1.0))); // printf ("T[%d]=%d\n",i,T[i]); } for (int i=0;i T1 (T,T+n), P1 (P,P+m); struct timeval s1, s2; gettimeofday (&s1, NULL); NaiveMatcher, std::not_equal_to >(T1,P1,TR,n,m); gettimeofday (&s2, NULL); printf ("NM: templated time %ld mikrosekund\n", s2.tv_usec - s1.tv_usec + (s2.tv_sec - s1.tv_sec) * 1000000); writeResults("result-NM-t",TR,r); gettimeofday (&s1, NULL); NaiveMatcher2 >(T,P,TR,n,m); gettimeofday (&s2, NULL); printf ("NM: templated without stl time %ld mikrosekund\n", s2.tv_usec - s1.tv_usec + (s2.tv_sec - s1.tv_sec) * 1000000); writeResults("result-NM-t",TR,r); gettimeofday (&s1, NULL); NM(T,P,TR,m,n); gettimeofday (&s2, NULL); printf ("NM: c function time %ld mikrosekund\n", s2.tv_usec - s1.tv_usec + (s2.tv_sec - s1.tv_sec) * 1000000); writeResults("result-NM",TR,r); int q=INT_MAX/d; int h=static_cast(pow(d,m-1)) % q; gettimeofday (&s1, NULL); RKM(T,P,TR,m,n,q,d,h); gettimeofday (&s2, NULL); printf ("RKM: c function time %ld mikrosekund\n", s2.tv_usec - s1.tv_usec + (s2.tv_sec - s1.tv_sec) * 1000000); writeResults("result-RKM",TR,r); delete [] T; delete [] TR; delete [] P; return 0; }