Example #1
0
static VALUE // bug?
rb_csa_search_l(VALUE self, VALUE oc, VALUE range)
{
    CSA *sa = csa_ptr(self);
    i64 ll,rr;
    int c;
    i64 ret;

    c = FIX2INT(oc);
#if USE_RANGE
    ll = FIX2LONG(range_first(range));
    rr = FIX2LONG(range_last(range));  if (range_exclude_end_p(range) == Qtrue) rr--;
#else
    if (RALEN(range) != 2) {
      return Qnil;
    }
    ll = FIX2LONG(RAPTR(range)[0]);
    rr = FIX2LONG(RAPTR(range)[1]);
#endif
    ret = sa->searchsub(c, sa, &ll, &rr);
    if (ret == -1) return Qnil;

#if USE_RANGE
    return rb_range_new(LONG2FIX(ll), LONG2FIX(rr), Qnil);
#else
    return rb_ary_new3(2, LONG2FIX(ll), LONG2FIX(rr));
#endif
}
Example #2
0
static VALUE
rb_csa_child_l(VALUE self, VALUE range)
{
    CSA *sa = csa_ptr(self);
    i64 l,r,ll,rr;
    int c,i;
    VALUE charset;
    i64 ret;

#if USE_RANGE
    ll = FIX2LONG(range_first(range));
    rr = FIX2LONG(range_last(range));  if (range_exclude_end_p(range) == Qtrue) rr--;
#else
    if (RALEN(range) != 2) {
      return Qnil;
    }
    ll = FIX2LONG(RAPTR(range)[0]);
    rr = FIX2LONG(RAPTR(range)[1]);
#endif
    l = r = -1;

    if (!rb_block_given_p()) charset = rb_ary_new();
    for (i=0; i<sa->m; i++) {
      c = sa->AtoC[i];
      l = ll;  r = rr;
      ret = sa->searchsub(c, sa, &l, &r);
      if (ret == 0) {
        if (rb_block_given_p()) {
            rb_yield(rb_ary_new3(2,INT2FIX(c),
#if USE_RANGE
                     rb_range_new(LONG2FIX(l), LONG2FIX(r), Qnil)));
#else
                     rb_ary_new3(2,LONG2FIX(l),LONG2FIX(r))));
#endif
        } else {
          rb_ary_push(charset,
            rb_ary_new3(2,INT2FIX(c),
#if USE_RANGE
            rb_range_new(LONG2FIX(l), LONG2FIX(r), Qnil)));
#else
            rb_ary_new3(2,LONG2FIX(l),LONG2FIX(r))));
#endif
        }
      }
    }
Example #3
0
cst_node cst_weiner_link(cst_node node, int c)
{
  CSA *csa;
  cst_node newnode;
  i64 ll, rr;
  i64 len;
  
  csa = newnode.csa = node.csa;

  ll = node.l;  rr = node.r;
  if (csa->searchsub(c, node.csa, &ll, &rr) != 0) {
    newnode.depth = -1;
    newnode.l = 1;
    newnode.r = 0;
  } else {
    newnode.depth = node.depth+1;
    newnode.l = ll;
    newnode.r = rr;
  }
  return newnode;

}