Class: R4r::RingBitsExt
- Inherits:
-
Object
- Object
- R4r::RingBitsExt
- Defined in:
- ext/r4r/ring_bits_ext/ring_bits_ext.c
Instance Method Summary collapse
-
#get(bit_index_value) ⇒ Object
Gets the bit at the specified index.
-
#initialize(capacity) ⇒ Object
constructor
Inits a new ring_bits_ext object.
-
#set(bit_index_value, value) ⇒ Object
Sets the bit at the specified index to value.
-
#size ⇒ Object
Returns an actual ring bits capacity.
Constructor Details
#initialize(capacity) ⇒ Object
Inits a new ring_bits_ext object.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'ext/r4r/ring_bits_ext/ring_bits_ext.c', line 54
static VALUE
ring_bits_ext_init(VALUE self, VALUE capacity) {
struct ring_bits_ext *ptr;
int ring_bits_ext_size = NUM2INT(capacity);
if (0 >= ring_bits_ext_size) {
rb_raise(rb_eArgError, "ring bit's size must be positive, got %i", ring_bits_ext_size);
return Qnil;
}
size_t count_of_words_required = ring_bits_ext_word_index(ring_bits_ext_size - 1) + 1;
Data_Get_Struct(self, struct ring_bits_ext, ptr);
ptr->size = count_of_words_required << ADDRESS_BITS_PER_WORD;
ptr->words = calloc(count_of_words_required, sizeof(uint64_t));
return self;
}
|
Instance Method Details
#get(bit_index_value) ⇒ Object
Gets the bit at the specified index.
143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'ext/r4r/ring_bits_ext/ring_bits_ext.c', line 143
static VALUE
ring_bits_ext_get(VALUE self, VALUE bit_index_value) {
struct ring_bits_ext *ptr;
Data_Get_Struct(self, struct ring_bits_ext, ptr);
int bit_index = NUM2INT(bit_index_value);
if (0 > bit_index) {
rb_raise(rb_eArgError, "ring bit's index must be positive, got %i", bit_index);
}
bool value = _ring_bits_ext_get(ptr, bit_index);
return value ? Qtrue : Qfalse;
}
|
#set(bit_index_value, value) ⇒ Object
Sets the bit at the specified index to value.
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'ext/r4r/ring_bits_ext/ring_bits_ext.c', line 110
static VALUE
ring_bits_ext_set(VALUE self, VALUE bit_index_value, VALUE value) {
struct ring_bits_ext *ptr;
Data_Get_Struct(self, struct ring_bits_ext, ptr);
int bit_index = NUM2INT(bit_index_value);
if (0 > bit_index) {
rb_raise(rb_eArgError, "ring bit's index must be positive, got %i", bit_index);
}
bool previous = _ring_bits_ext_set(ptr, bit_index, value == Qtrue);
return previous ? Qtrue : Qfalse;
}
|
#size ⇒ Object
Returns an actual ring bits capacity.
76 77 78 79 80 81 |
# File 'ext/r4r/ring_bits_ext/ring_bits_ext.c', line 76
static VALUE
ring_bits_ext_get_size(VALUE self) {
struct ring_bits_ext *ptr;
Data_Get_Struct(self, struct ring_bits_ext, ptr);
return SIZET2NUM(ptr->size);
}
|