Example #1
0
static VALUE
//rb_csa_text(VALUE self, VALUE oi, VALUE oj)
rb_csa_text(VALUE self, VALUE range)
{
    CSA *sa = csa_ptr(self);
    i64 i,j,n;
    uchar *buf;

#if USE_RANGE
    i = FIX2LONG(range_first(range));
    j = FIX2LONG(range_last(range));  if (range_exclude_end_p(range) == Qtrue) j--;
#else
//    i = FIX2LONG(oi);
//    j = FIX2LONG(oj);
    if (RALEN(range) != 2) {
      return Qnil;
    }
    i = FIX2LONG(RAPTR(range)[0]);
    j = FIX2LONG(RAPTR(range)[1]);
#endif
    n = sa->n;

    if (i < 0 || i > n || j < 0 || j > n) {    // error
      return Qnil;
    }

    buf = (uchar *)alloca(j-i+1+1);
    sa->text(buf, sa, i, j);
    buf[j-i+1] = 0;
    return rb_str_new(buf, j-i+1);
}
Example #2
0
int extract(void *index, ulong from, ulong to, uchar **snippet,
			ulong *snippet_length)
{
  CSA *csa;
  uchar *text;
  i64 i,len;

  csa = (CSA *)index;

  from++;  to++;
  if (to > csa->n) to = csa->n;

  len = to - from + 1;
  text = malloc(len);

  csa->text(text,csa,from,to);

  *snippet = text;
  *snippet_length = (ulong)len;
  return 0;
}
Example #3
0
int main(int argc, char *argv[])
{
  i64 i,n;
  CSA csa;
  mytimestruct before,after;
  double t;

   if (argc<2) {
      fprintf(stderr, "syntax: suftest file\n");
      return 1;
   }

   csa_read(&csa,argc,argv);
   n = csa.n;

   mygettime(&before);
   {
     int m;
     FILE *out;
     out = fopen("output.dec","w");
     i = 0;
     while (i < n) {
       if ((i/PAGE) % PAGE == 0) {
         fprintf(stderr,"%ld \r",i/PAGE);  fflush(stderr);
       }
       m = PAGE;
       if (i+m >= n) m = n-i;
       csa.text(buf,&csa,i,i+m-1);
       fwrite(buf,1,m,out);
       i += m;
     }
     fwrite(buf,1,0,out);
     fclose(out);
   }
   mygettime(&after);
   t = mylaptime(&before,&after);
   fprintf(stderr,"time %f sec\n",t);
   return 0;
}