Exemple #1
0
int locate(void *index, uchar *pattern, ulong length, ulong **occ, 
		   ulong *numocc)
{
  CSA *csa;
  i64 l,r;
  ulong *buf,*buf2;
  ulong i,oc;
  i64 mlen;

  csa = (CSA *)index;
  mlen = csa->search(pattern, length, csa, &l, &r);
  if (mlen < length) {
    *numocc = 0;
    return 0;
  }
  oc = (ulong)(r - l + 1);

  buf = malloc((*numocc) * sizeof(ulong));
  if (buf == NULL) {
    printf("locate: not enough mem.\n");
    exit(1);
  }

  for (i=0; i<oc; i++) {
    buf[i] = csa->lookup(csa,l + i);
  }

  *numocc = oc;
  *occ = buf;
  return 0;
}
Exemple #2
0
static VALUE
rb_csa_lookup(VALUE self, VALUE oi)
{
    CSA *sa = csa_ptr(self);
    i64 i, j, n;

    i = FIX2LONG(oi);
    n = sa->n;

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

    j = sa->lookup(sa, i);

    return LONG2FIX(j);
}