Class: NoyesC::ArrayList

Inherits:
Object
  • Object
show all
Defined in:
lib/cext/array_list.c

Instance Method Summary collapse

Constructor Details

#initializeObject



13
14
15
16
17
18
# File 'lib/cext/array_list.c', line 13

static VALUE t_init(VALUE self) {
  Clist *st = clist_new();
  VALUE stv = Data_Wrap_Struct(cArrayList, 0, free_clist, st);
  rb_iv_set(self, "@clist", stv);
  return self;
}

Instance Method Details

#addObject



27
28
29
30
31
32
33
# File 'lib/cext/array_list.c', line 27

static VALUE t_add(VALUE self, VALUE obj) {
  Clist *array;
  VALUE arrayv = rb_iv_get(self, "@clist");
  Data_Get_Struct(arrayv, Clist, array);
  clist_add(array, (void*)obj);
  return Qnil;
}

#getObject



35
36
37
38
39
40
# File 'lib/cext/array_list.c', line 35

static VALUE t_get(VALUE self, VALUE obj) {
  Clist *array;
  VALUE arrayv = rb_iv_get(self, "@clist");
  Data_Get_Struct(arrayv, Clist, array);
  return (VALUE)clist_get(array, FIX2INT(obj));
}

#removeObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cext/array_list.c', line 42

static VALUE t_remove(VALUE self, VALUE start, VALUE finish) {
  Clist *array;
  VALUE arrayv = rb_iv_get(self, "@clist");
  Data_Get_Struct(arrayv, Clist, array);
  int b = FIX2INT(start);
  int e = FIX2INT(finish);
  if (clist_remove(array, b, e)) {
    int s = clist_size(array);
    rb_raise(rb_eArgError, "start = %d, finish = %d with size =  %d", b, e, s);
   }
  return Qnil;
}

#sizeObject



20
21
22
23
24
25
# File 'lib/cext/array_list.c', line 20

static VALUE t_size(VALUE self) {
  Clist *array;
  VALUE arrayv = rb_iv_get(self, "@clist");
  Data_Get_Struct(arrayv, Clist, array);
  return INT2FIX(clist_size(array));
}