ext/cumo/narray/step.c in cumo-0.1.0 vs ext/cumo/narray/step.c in cumo-0.1.1
- old
+ new
@@ -22,16 +22,16 @@
#ifndef DBL_EPSILON
#define DBL_EPSILON 2.2204460492503131e-16
#endif
-static ID id_beg, id_end, id_len, id_step, id_excl;
+static ID cumo_id_beg, cumo_id_end, cumo_id_len, cumo_id_step, cumo_id_excl;
-//#define EXCL(r) RTEST(rb_ivar_get((r), id_excl))
+//#define EXCL(r) RTEST(rb_ivar_get((r), cumo_id_excl))
#define EXCL(r) RTEST(rb_funcall((r), rb_intern("exclude_end?"), 0))
-#define SET_EXCL(r,v) rb_ivar_set((r), id_excl, (v) ? Qtrue : Qfalse)
+#define SET_EXCL(r,v) rb_ivar_set((r), cumo_id_excl, (v) ? Qtrue : Qfalse)
static void
step_init(
VALUE self,
VALUE beg,
@@ -47,31 +47,31 @@
}
if (RTEST(rb_funcall(len,rb_intern("<"),1,INT2FIX(0)))) {
rb_raise(rb_eRangeError,"length must be non negative");
}
}
- rb_ivar_set(self, id_beg, beg);
- rb_ivar_set(self, id_end, end);
- rb_ivar_set(self, id_len, len);
- rb_ivar_set(self, id_step, step);
+ rb_ivar_set(self, cumo_id_beg, beg);
+ rb_ivar_set(self, cumo_id_end, end);
+ rb_ivar_set(self, cumo_id_len, len);
+ rb_ivar_set(self, cumo_id_step, step);
SET_EXCL(self, excl);
}
static VALUE
-nary_step_new2(
+cumo_na_step_new2(
VALUE range,
VALUE step,
VALUE len
)
{
VALUE beg, end, excl;
- VALUE self = rb_obj_alloc(na_cStep);
+ VALUE self = rb_obj_alloc(cumo_na_cStep);
- //beg = rb_ivar_get(range, id_beg);
- beg = rb_funcall(range, id_beg, 0);
- //end = rb_ivar_get(range, id_end);
- end = rb_funcall(range, id_end, 0);
+ //beg = rb_ivar_get(range, cumo_id_beg);
+ beg = rb_funcall(range, cumo_id_beg, 0);
+ //end = rb_ivar_get(range, cumo_id_end);
+ end = rb_funcall(range, cumo_id_end, 0);
excl = rb_funcall(range, rb_intern("exclude_end?"), 0);
step_init(self, beg, end, step, len, excl);
return self;
}
@@ -94,24 +94,24 @@
{
VALUE a, b=Qnil, c=Qnil, d=Qnil, e=Qnil;
rb_scan_args(argc, argv, "13", &a, &b, &c, &d);
/* Selfs are immutable, so that they should be initialized only once. */
- if (rb_ivar_defined(self, id_beg)) {
+ if (rb_ivar_defined(self, cumo_id_beg)) {
rb_name_error(rb_intern("initialize"), "`initialize' called twice");
}
if (rb_obj_is_kind_of(a,rb_cRange)) {
if (argc>3) {
rb_raise(rb_eArgError, "extra argument");
}
d = c;
c = b;
e = rb_funcall(a, rb_intern("exclude_end?"), 0);
- //b = rb_ivar_get(a, id_end);
- b = rb_funcall(a, id_end, 0);
- //a = rb_ivar_get(a, id_beg);
- a = rb_funcall(a, id_beg, 0);
+ //b = rb_ivar_get(a, cumo_id_end);
+ b = rb_funcall(a, cumo_id_end, 0);
+ //a = rb_ivar_get(a, cumo_id_beg);
+ a = rb_funcall(a, cumo_id_beg, 0);
}
step_init(self, a, b, c, d, e);
return Qnil;
}
@@ -124,11 +124,11 @@
*/
static VALUE
step_first( VALUE self )
{
- return rb_ivar_get(self, id_beg);
+ return rb_ivar_get(self, cumo_id_beg);
}
/*
* call-seq:
* step.end => obj
@@ -138,11 +138,11 @@
*/
static VALUE
step_last( VALUE self )
{
- return rb_ivar_get(self, id_end);
+ return rb_ivar_get(self, cumo_id_end);
}
/*
* call-seq:
* step.length => obj
@@ -152,11 +152,11 @@
*/
static VALUE
step_length( VALUE self )
{
- return rb_ivar_get(self, id_len);
+ return rb_ivar_get(self, cumo_id_len);
}
/*
* call-seq:
* step.step => obj
@@ -165,11 +165,11 @@
*/
static VALUE
step_step( VALUE self )
{
- return rb_ivar_get(self, id_step);
+ return rb_ivar_get(self, cumo_id_step);
}
/*
* call-seq:
* step.exclude_end? => true or false
@@ -177,11 +177,11 @@
* Returns <code>true</code> if <i>step</i> excludes its end value.
*/
static VALUE
step_exclude_end_p(VALUE self)
{
- return RTEST(rb_ivar_get(self, id_excl)) ? Qtrue : Qfalse;
+ return RTEST(rb_ivar_get(self, cumo_id_excl)) ? Qtrue : Qfalse;
}
/*
* call-seq:
@@ -190,26 +190,26 @@
* Returns the iteration parameters of <i>step</i>. If
* <i>array_sizse</i> is given, negative array index is considered.
*/
void
-nary_step_array_index(VALUE self, size_t ary_size,
+cumo_na_step_array_index(VALUE self, size_t ary_size,
size_t *plen, ssize_t *pbeg, ssize_t *pstep)
{
size_t len;
ssize_t beg=0, step=1;
VALUE vbeg, vend, vstep, vlen;
ssize_t end=ary_size;
- //vbeg = rb_ivar_get(self, id_beg);
- //vend = rb_ivar_get(self, id_end);
- vlen = rb_ivar_get(self, id_len);
- vstep = rb_ivar_get(self, id_step);
- vbeg = rb_funcall(self, id_beg, 0);
- vend = rb_funcall(self, id_end, 0);
- //vlen = rb_funcall(self, id_len, 0);
- //vstep = rb_funcall(self, id_step, 0);
+ //vbeg = rb_ivar_get(self, cumo_id_beg);
+ //vend = rb_ivar_get(self, cumo_id_end);
+ vlen = rb_ivar_get(self, cumo_id_len);
+ vstep = rb_ivar_get(self, cumo_id_step);
+ vbeg = rb_funcall(self, cumo_id_beg, 0);
+ vend = rb_funcall(self, cumo_id_end, 0);
+ //vlen = rb_funcall(self, cumo_id_len, 0);
+ //vstep = rb_funcall(self, cumo_id_step, 0);
if (RTEST(vbeg)) {
beg = NUM2SSIZET(vbeg);
if (beg<0) {
beg += ary_size;
@@ -327,27 +327,27 @@
if (pstep) *pstep = step;
}
void
-nary_step_sequence( VALUE self, size_t *plen, double *pbeg, double *pstep )
+cumo_na_step_sequence( VALUE self, size_t *plen, double *pbeg, double *pstep )
{
VALUE vbeg, vend, vstep, vlen;
double dbeg, dend, dstep=1, dsize, err;
size_t size, n;
- //vbeg = rb_ivar_get(self, id_beg);
- vbeg = rb_funcall(self, id_beg, 0);
+ //vbeg = rb_ivar_get(self, cumo_id_beg);
+ vbeg = rb_funcall(self, cumo_id_beg, 0);
dbeg = NUM2DBL(vbeg);
- //vend = rb_ivar_get(self, id_end);
- vend = rb_funcall(self, id_end, 0);
+ //vend = rb_ivar_get(self, cumo_id_end);
+ vend = rb_funcall(self, cumo_id_end, 0);
- vlen = rb_ivar_get(self, id_len);
- vstep = rb_ivar_get(self, id_step);
- //vlen = rb_funcall(self, id_len ,0);
- //vstep = rb_funcall(self, id_step,0);
+ vlen = rb_ivar_get(self, cumo_id_len);
+ vstep = rb_ivar_get(self, cumo_id_step);
+ //vlen = rb_funcall(self, cumo_id_len ,0);
+ //vstep = rb_funcall(self, cumo_id_step,0);
if (RTEST(vlen)) {
size = NUM2SIZET(vlen);
if (!RTEST(vstep)) {
@@ -404,11 +404,11 @@
{
VALUE a;
double beg, step;
size_t i, size;
- a = nary_step_parameters( self, Qnil );
+ a = cumo_na_step_parameters( self, Qnil );
beg = NUM2DBL(RARRAY_PTR(a)[0]);
step = NUM2DBL(RARRAY_PTR(a)[1]);
size = NUM2SIZET(RARRAY_PTR(a)[2]);
for (i=0; i<size; i++) {
@@ -419,56 +419,56 @@
*/
static VALUE
range_with_step( VALUE range, VALUE step )
{
- return nary_step_new2( range, step, Qnil );
+ return cumo_na_step_new2( range, step, Qnil );
}
static VALUE
range_with_length( VALUE range, VALUE len )
{
- return nary_step_new2( range, Qnil, len );
+ return cumo_na_step_new2( range, Qnil, len );
}
static VALUE
-nary_s_step( int argc, VALUE *argv, VALUE mod )
+cumo_na_s_step( int argc, VALUE *argv, VALUE mod )
{
- VALUE self = rb_obj_alloc(na_cStep);
+ VALUE self = rb_obj_alloc(cumo_na_cStep);
step_initialize(argc, argv, self);
return self;
}
void
-Init_cumo_nary_step()
+Init_cumo_na_step()
{
- na_cStep = rb_define_class_under(cNArray, "Step", rb_cObject);
- rb_include_module(na_cStep, rb_mEnumerable);
- rb_define_method(na_cStep, "initialize", step_initialize, -1);
+ cumo_na_cStep = rb_define_class_under(cNArray, "Step", rb_cObject);
+ rb_include_module(cumo_na_cStep, rb_mEnumerable);
+ rb_define_method(cumo_na_cStep, "initialize", step_initialize, -1);
- //rb_define_method(na_cStep, "each", step_each, 0);
+ //rb_define_method(cumo_na_cStep, "each", step_each, 0);
- rb_define_method(na_cStep, "first", step_first, 0);
- rb_define_method(na_cStep, "last", step_last, 0);
- rb_define_method(na_cStep, "begin", step_first, 0);
- rb_define_method(na_cStep, "end", step_last, 0);
- rb_define_method(na_cStep, "step", step_step, 0);
- rb_define_method(na_cStep, "length", step_length, 0);
- rb_define_method(na_cStep, "size", step_length, 0);
- rb_define_method(na_cStep, "exclude_end?", step_exclude_end_p, 0);
- //rb_define_method(na_cStep, "to_s", step_to_s, 0);
- //rb_define_method(na_cStep, "inspect", step_inspect, 0);
- //rb_define_method(na_cStep, "parameters", nary_step_parameters, 1);
+ rb_define_method(cumo_na_cStep, "first", step_first, 0);
+ rb_define_method(cumo_na_cStep, "last", step_last, 0);
+ rb_define_method(cumo_na_cStep, "begin", step_first, 0);
+ rb_define_method(cumo_na_cStep, "end", step_last, 0);
+ rb_define_method(cumo_na_cStep, "step", step_step, 0);
+ rb_define_method(cumo_na_cStep, "length", step_length, 0);
+ rb_define_method(cumo_na_cStep, "size", step_length, 0);
+ rb_define_method(cumo_na_cStep, "exclude_end?", step_exclude_end_p, 0);
+ //rb_define_method(cumo_na_cStep, "to_s", step_to_s, 0);
+ //rb_define_method(cumo_na_cStep, "inspect", step_inspect, 0);
+ //rb_define_method(cumo_na_cStep, "parameters", cumo_na_step_parameters, 1);
rb_define_method(rb_cRange, "%", range_with_step, 1);
rb_define_method(rb_cRange, "*", range_with_length, 1);
- rb_define_singleton_method(cNArray, "step", nary_s_step, -1);
+ rb_define_singleton_method(cNArray, "step", cumo_na_s_step, -1);
- id_beg = rb_intern("begin");
- id_end = rb_intern("end");
- id_len = rb_intern("length");
- id_step = rb_intern("step");
- id_excl = rb_intern("excl");
+ cumo_id_beg = rb_intern("begin");
+ cumo_id_end = rb_intern("end");
+ cumo_id_len = rb_intern("length");
+ cumo_id_step = rb_intern("step");
+ cumo_id_excl = rb_intern("excl");
}