class SparseArrayInt
Public Instance Methods
[](p1)
click to toggle source
static VALUE sparse_array_int_get(VALUE self, VALUE ri) { spar_table *table; spar_index_t i = NUM2UINT(ri); st_data_t res = 0; GetSparseArrayInt(self, table); if (spar_lookup(table, i, &res)) { return st_data2num(res); } return Qnil; }
[]=(p1, p2)
click to toggle source
static VALUE sparse_array_int_set(VALUE self, VALUE ri, VALUE val) { spar_table *table; spar_index_t i = NUM2UINT(ri); st_data_t val_ = num2st_data(val); GetSparseArrayInt(self, table); spar_insert(table, i, val_); return val; }
clear()
click to toggle source
static VALUE sparse_array_int_clear(VALUE self) { spar_table *table; GetSparseArrayInt(self, table); spar_clear(table); return self; }
delete(p1)
click to toggle source
static VALUE sparse_array_int_del(VALUE self, VALUE ri) { spar_table *table; spar_index_t i = NUM2UINT(ri); st_data_t res = 0; GetSparseArrayInt(self, table); if (spar_delete(table, i, &res)) return st_data2num(res); return Qnil; }
each()
click to toggle source
static VALUE sparse_array_int_each(VALUE self) { spar_table *table; VALUE y[2] = {Qnil, Qnil}; RETURN_ENUMERATOR(self, 0, 0); GetSparseArrayInt(self, table); SPAR_FOREACH_START(table); y[0] = UINT2NUM(entry->key); y[1] = st_data2num((VALUE)value); rb_yield_values2(2, y); SPAR_FOREACH_END(); return self; }
Also aliased as: each_pair
each_key()
click to toggle source
static VALUE sparse_array_int_each_key(VALUE self) { spar_table *table; RETURN_ENUMERATOR(self, 0, 0); GetSparseArrayInt(self, table); SPAR_FOREACH_START(table); (void)value; rb_yield(UINT2NUM(entry->key)); SPAR_FOREACH_END(); return self; }
each_value()
click to toggle source
static VALUE sparse_array_int_each_value(VALUE self) { spar_table *table; RETURN_ENUMERATOR(self, 0, 0); GetSparseArrayInt(self, table); SPAR_FOREACH_START(table); rb_yield(st_data2num(value)); SPAR_FOREACH_END(); return self; }
empty?()
click to toggle source
static VALUE sparse_array_int_empty_p(VALUE self) { spar_table *table; GetSparseArrayInt(self, table); return table->num_entries ? Qfalse : Qtrue; }
fetch(p1, p2)
click to toggle source
static VALUE sparse_array_int_fetch(VALUE self, VALUE ri, VALUE def) { spar_table *table; spar_index_t i = NUM2UINT(ri); st_data_t res = 0; GetSparseArrayInt(self, table); if (spar_lookup(table, i, &res)) return st_data2num(res); else return def; }
include?(p1)
click to toggle source
static VALUE sparse_array_int_include(VALUE self, VALUE ri) { spar_table *table; spar_index_t i = NUM2UINT(ri); st_data_t res = Qnil; GetSparseArrayInt(self, table); if (spar_lookup(table, i, &res)) return Qtrue; else return Qfalse; }
Also aliased as: has_key?
initialize_copy(p1)
click to toggle source
static VALUE sparse_array_int_init_copy(VALUE self, VALUE orig) { spar_table *table; spar_table *original; GetSparseArrayInt(self, table); GetSparseArrayInt(orig, original); rb_obj_init_copy(self, orig); spar_copy_to(original, table); return self; }
inspect()
click to toggle source
static VALUE sparse_array_int_inspect(VALUE self) { spar_table *table; GetSparseArrayInt(self, table); if (table->num_entries == 0) return rb_usascii_str_new2("<SparseArrayInt>"); return rb_exec_recursive(sparse_array_int_inspect_rec, self, 0); }
keys()
click to toggle source
static VALUE sparse_array_int_keys(VALUE self) { spar_table *table; VALUE res; GetSparseArrayInt(self, table); res = rb_ary_new2(table->num_entries); SPAR_FOREACH_START(table); (void)value; rb_ary_push(res, UINT2NUM(entry->key)); SPAR_FOREACH_END(); return res; }
size()
click to toggle source
static VALUE sparse_array_int_size(VALUE self) { spar_table *table; GetSparseArrayInt(self, table); return UINT2NUM(table->num_entries); }
Also aliased as: count
values()
click to toggle source
static VALUE sparse_array_int_values(VALUE self) { spar_table *table; VALUE res; GetSparseArrayInt(self, table); res = rb_ary_new2(table->num_entries); SPAR_FOREACH_START(table); rb_ary_push(res, st_data2num((VALUE)value)); SPAR_FOREACH_END(); return res; }