Example #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;
}
Example #2
0
int count(void *index, uchar *pattern, ulong length, ulong *numocc)
{
  CSA *csa;
  i64 l,r;
  i64 mlen;

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

  return 0;
}
Example #3
0
static VALUE
rb_csa_search(VALUE self, VALUE okey)
{
    CSA *sa = csa_ptr(self);
    i64 n, l, keylen;
    i64 i[2];
    uchar *key;

    key = StringValueCStr(okey);
    keylen = RSLEN(okey);

    if (sa->search(key, keylen, sa, &i[0], &i[1]) < keylen) return Qnil;

#if USE_RANGE
    return rb_range_new(LONG2FIX(i[0]), LONG2FIX(i[1]), Qnil);
#else
    return rb_ary_new3(2, LONG2FIX(i[0]), LONG2FIX(i[1]));
#endif
}
Example #4
0
cst_node cst_parent(cst_node node)
{
  CSA *csa;
  uchar *label;
  cst_node parent;
  i64 l, r;
  i64 len;

  csa = node.csa;
  parent.csa = csa;
  parent.depth = node.depth-1;

  label = cst_pathlabel(node);
  l = node.l;  r = node.r;
  if (csa->search(label, parent.depth, csa, &l, &r) != parent.depth) {
    printf("cst_parent: ???\n");
  }
  parent.l = l;  parent.r = r;

  free(label);
  return parent;
}