Пример #1
0
int search(unsigned char *P, int m, unsigned char *T, int n) {
   int i, s, k, count, qsf[SIGMA], qsb[SIGMA];
   unsigned char R[XSIZE];
   
   BEGIN_PREPROCESSING
   reverse(P,m,R);
   preQsBc(P, m, qsf);
   preQsBc(R, m, qsb);
   int z = m+m/2;
   END_PREPROCESSING

   BEGIN_SEARCHING
   i = 0;
   count = 0;
   while(i<=n-m) {
      k=0;
      while(k<m && P[k]==T[i+k]) k++;
      if(k==m) count++;
      i += ( qsf[T[i+m]]>z-qsb[T[i+z-1]] ? z : qsf[T[i+m]] );
   }
   END_SEARCHING
   return count;
}
Пример #2
0
char* Sbmhs2(char * textt,char *patt,int n, int m)//SUNDAYËã·¨£¬ÓÖ³Æ quich search 
{
	int j,qsBc[ASIZE];
	unsigned char *text,*pat;
	text = (unsigned char*)textt;
	pat = (unsigned char*)patt;
    if(*pat == '\0') { OUTPUT(0);return textt;}; 

	/* preprocessing */
	preQsBc((char*)pat,m,qsBc);

	/* Searching */
	j=0;
	while (j<=n-m)
	{
		if (memcmp(pat,text+j,m)==0)
			OUTPUT(j);
		j+=qsBc[text[j+m]]; //shift
	}
	SRET(j);
}
Пример #3
0
int search(unsigned char *x, int m, unsigned char *y, int n) {
   int j, bmBc[SIGMA], qsBc[SIGMA], count;

   /* Preprocessing */
   BEGIN_PREPROCESSING
   preBmBc(x, m, bmBc);
   preQsBc(x, m, qsBc);
   END_PREPROCESSING

   count = 0;
   /* Searching */
   BEGIN_SEARCHING
   j = 0;
   while (j<= n - m) {
      if (memcmp(x, y + j, m) == 0)
         OUTPUT(j);
      j += MAX(bmBc[y[j + m - 1]], qsBc[y[j + m]]);
   }
   END_SEARCHING
   return count;
}
Пример #4
0
char*  Ssmith2(char * textt,char *patt,int n, int m)//smith ╦сие 
{
	int j,bmBc[ASIZE],qsBc[ASIZE];
	unsigned char * text,*pat;
	text = (unsigned char*)textt;
	pat = (unsigned char*)patt;
    if(*pat == '\0') { OUTPUT(0);return textt;}; 


	/* preprocessing */
	preBmBc((char*)pat,m,bmBc);
	preQsBc((char*)pat,m,qsBc);

	/* searching */
	j=0;
	while (j<=n-m)
	{
		if (memcmp(pat,text+j,m)==0)
			OUTPUT(j);
		j+=MAX(bmBc[text[j+m-1]],qsBc[text[j+m]]);
	}
	SRET(j);
}