Class: SparseArrayInt

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
ext/sp_ar.c

Instance Method Summary collapse

Instance Method Details

#[](ri) ⇒ Object



635
636
637
638
639
640
641
642
643
644
645
646
# File 'ext/sp_ar.c', line 635

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;
}

#[]=(ri, val) ⇒ Object



674
675
676
677
678
679
680
681
682
683
# File 'ext/sp_ar.c', line 674

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;
}

#clearObject



713
714
715
716
717
718
719
720
# File 'ext/sp_ar.c', line 713

static VALUE
sparse_array_int_clear(VALUE self)
{
    spar_table *table;
    GetSparseArrayInt(self, table);
    spar_clear(table);
    return self;
}

#countObject



697
698
699
700
701
702
703
# File 'ext/sp_ar.c', line 697

static VALUE
sparse_array_int_size(VALUE self)
{
    spar_table *table;
    GetSparseArrayInt(self, table);
    return UINT2NUM(table->num_entries);
}

#delete(ri) ⇒ Object



685
686
687
688
689
690
691
692
693
694
695
# File 'ext/sp_ar.c', line 685

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;
}

#eachObject



749
750
751
752
753
754
755
756
757
758
759
760
761
762
# File 'ext/sp_ar.c', line 749

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;
}

#each_keyObject



764
765
766
767
768
769
770
771
772
773
774
775
# File 'ext/sp_ar.c', line 764

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_pairObject



749
750
751
752
753
754
755
756
757
758
759
760
761
762
# File 'ext/sp_ar.c', line 749

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;
}

#each_valueObject



777
778
779
780
781
782
783
784
785
786
787
# File 'ext/sp_ar.c', line 777

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?Boolean

Returns:

  • (Boolean)


705
706
707
708
709
710
711
# File 'ext/sp_ar.c', line 705

static VALUE
sparse_array_int_empty_p(VALUE self)
{
    spar_table *table;
    GetSparseArrayInt(self, table);
    return table->num_entries ? Qfalse : Qtrue;
}

#fetch(ri, def) ⇒ Object



661
662
663
664
665
666
667
668
669
670
671
672
# File 'ext/sp_ar.c', line 661

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;
}

#has_key?(ri) ⇒ Boolean

Returns:

  • (Boolean)


648
649
650
651
652
653
654
655
656
657
658
659
# File 'ext/sp_ar.c', line 648

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;
}

#include?(ri) ⇒ Boolean

Returns:

  • (Boolean)


648
649
650
651
652
653
654
655
656
657
658
659
# File 'ext/sp_ar.c', line 648

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;
}

#initialize_copy(copy) ⇒ Object



789
790
791
792
793
794
795
796
797
798
799
# File 'ext/sp_ar.c', line 789

static VALUE
sparse_array_int_init_copy(VALUE self, VALUE copy)
{
    spar_table *table;
    spar_table *copied;
    GetSparseArrayInt(self, table);
    GetSparseArrayInt(copy, copied);
    rb_obj_init_copy(self, copy);
    spar_copy_to(table, copied);
    return copy;
}

#inspectObject



823
824
825
826
827
828
829
830
831
# File 'ext/sp_ar.c', line 823

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);
}

#keysObject



722
723
724
725
726
727
728
729
730
731
732
733
734
# File 'ext/sp_ar.c', line 722

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;
}

#sizeObject



697
698
699
700
701
702
703
# File 'ext/sp_ar.c', line 697

static VALUE
sparse_array_int_size(VALUE self)
{
    spar_table *table;
    GetSparseArrayInt(self, table);
    return UINT2NUM(table->num_entries);
}

#valuesObject



736
737
738
739
740
741
742
743
744
745
746
747
# File 'ext/sp_ar.c', line 736

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;
}