示例#1
0
	void csa_decodeall(unsigned char *p,CSA *SA) {
		int *I;
		int i,n,pos;
		int x,b,d;
		unsigned short *B;
		n = SA->n;
		I =(int *)malloc((n+1)*sizeof(*I));
		if (I == NULL) {perror("decodeall");  exit(1);}

		B = SA->B;
		x = -1;  b = 0;
		for (i=1; i<=n; i++) {
			b += DECODENUM(B,b,&d);
			x += d;
			if (x > n) {
				x = -1;  i--;
			}
			else {
				I[i] = x;
			}
		}
		pos = csa_inverse(SA,1);
		for (i=1; i<=n; i++) {
			if (pos < 1 || pos > n) {
				printf("i %d pos %d\n",i,pos);
			}
			*p++ = csa_T(SA,pos);
			pos = I[pos];
		}
	}
/*///////////////////////
//Accessing the indexed//
///////////////////////*/
int display(void *index, UCHAR *pattern, ULONG length, ULONG numc, ULONG *numocc, UCHAR **snippet_text, ULONG **snippet_lengths) {
  int l,r;
  int pos;
  ULONG *occ, i, j, from, to, len, x;
  UCHAR *text_aux;
  CSA *SA=(CSA *) index;
  csa_bsearch(pattern,length,SA,&l,&r);
  *numocc = r-l+1;
  occ = csa_batchlookup2(SA,l,r);
  *snippet_lengths = (ULONG *) malloc((*numocc)*sizeof(ULONG));
  if (!(*snippet_lengths)) return 1;
  *snippet_text = (UCHAR *) malloc((*numocc)*(length+2*numc)*sizeof(UCHAR));
  if (!(*snippet_text)) return 1;
  text_aux=*snippet_text;

  for (i=0;i<(*numocc);i++) {
    x=occ[i];
    if (x>numc) from = x-numc;
    else from=0;
    to= ((int)(x+length+numc-1)<(int)(SA->n-1)?(x+length+numc-1):(SA->n-1));
    len =to-from+1;
    pos = csa_inverse(SA,from+1);
    for (j=0; (int)j<(int)len;j++) {
      text_aux[j] = csa_T(SA,pos);
      pos= csa_psi(SA,pos);
    }
    text_aux+=length+2*numc;
    (*snippet_lengths)[i] = len;
  }
  free(occ);
  return 0;
}
示例#3
0
	void csa_decode1line(unsigned char *p,CSA *SA,int suf,int maxlen) {
		int i,k,m,pos;
		unsigned char *tmp;

		m = maxlen*2;
		tmp = (unsigned char *)malloc(m+1);
		if (tmp==NULL) {perror("csa_decode1line");  exit(1);}

		k = suf - maxlen;  if (k <= 0) k = 1;
		pos = csa_inverse(SA,k);

		i = 0;
		while (i < m) {
			tmp[i] = csa_T(SA,pos);
			pos = csa_psi(SA,pos);
			i++;
		}
		for (i = suf-k;  i < m;  i++) {
			if (tmp[i] == 0x0a) {i--;  break;}
		}
		m = i;
		for (i = suf-k;  i >= 0;  i--) {
			if (tmp[i] == 0x0a) {i++;  break;}
		}
		if (m-i > maxlen) i = m-maxlen;
		while (i < m) *p++ = tmp[i++];
		*p = 0;
		free(tmp);
	}
示例#4
0
	void csa_decode2(unsigned char *p,CSA *SA,int pos,int len) {
		int i;
		i = 0;
		while (i < len) {
			*p++ = csa_T(SA,pos);
			pos = csa_psi(SA,pos);
			i++;
		}
	}
示例#5
0
	void csa_decode(unsigned char *p,CSA *SA,int suf,int len) {
		int pos;
		int i;
		pos = csa_inverse(SA,suf);
		i = 0;
		while (i < len) {
			*p++ = csa_T(SA,pos);
			pos = csa_psi(SA,pos);
			i++;
		}
	}
int extract(void *index, ULONG from, ULONG to, UCHAR **snippet, ULONG *snippet_length){
   CSA *SA=(CSA *) index;
   ULONG n = SA->n;
   int pos;
   if (to >= n) to=n-1;
   if (from > to) {
     *snippet = NULL;
     *snippet_length=0;
   } else {
     ULONG j;
     ULONG len =to-from+1;
     *snippet = (UCHAR *) malloc((len)*sizeof(UCHAR));
     if (!(*snippet)) return 1;
     pos = csa_inverse(SA,from+1);
     for (j=0; j<len;j++) {
       (*snippet)[j]=csa_T(SA,pos);
       pos= csa_psi(SA,pos);
     }
     (*snippet_length)=len;
   }
   return 0;
}
示例#7
0
	int extract(void *index, ulong from, ulong to, uchar **snippet, ulong *snippet_length) {
		CSA *SA=(CSA *) index;
		ulong n = SA->n;
		int pos;
		if (to >= n) to=n-1;
		if (from > to) {
			*snippet = NULL;
			*snippet_length=0;
		}
		else {
			ulong j;
			ulong len =to-from+1;
			*snippet = (uchar *) malloc((len)*sizeof(uchar));
			if (!(*snippet)) return 1;
			pos = csa_inverse(SA,from+1);
			for (j=0; j<len;j++) {
				(*snippet)[j]=csa_T(SA,pos);
				pos= csa_psi(SA,pos);
			}
			(*snippet_length)=len;
		}
		return 0;
	}
示例#8
0
	size_t TextIndexCSA::getT(size_t i) const{
		return csa_T(csa,i+1);
	}