ingramj-bitarray 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/bitarray.gemspec +1 -1
  3. data/ext/bitarray.c +88 -1
  4. metadata +1 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/bitarray.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{bitarray}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["James E. Ingram"]
data/ext/bitarray.c CHANGED
@@ -138,6 +138,11 @@ rb_bitarray_alloc(VALUE klass)
138
138
  }
139
139
 
140
140
 
141
+ /* call-seq:
142
+ * BitArray.new(size)
143
+ *
144
+ * Return a new BitArray or the specified size.
145
+ */
141
146
  static VALUE
142
147
  rb_bitarray_initialize(VALUE self, VALUE size)
143
148
  {
@@ -155,6 +160,12 @@ rb_bitarray_initialize(VALUE self, VALUE size)
155
160
  }
156
161
 
157
162
 
163
+ /* call-seq:
164
+ * bitarray.clone -> a_bitarray
165
+ * bitarray.dup -> a_bitarray
166
+ *
167
+ * Produces a copy of _bitarray_.
168
+ */
158
169
  static VALUE
159
170
  rb_bitarray_clone(VALUE self)
160
171
  {
@@ -174,6 +185,12 @@ rb_bitarray_clone(VALUE self)
174
185
  }
175
186
 
176
187
 
188
+ /* call-seq:
189
+ * bitarray.size -> int
190
+ * bitarray.length -> int
191
+ *
192
+ * Returns the number of bits in _bitarray_.
193
+ */
177
194
  static VALUE
178
195
  rb_bitarray_size(VALUE self)
179
196
  {
@@ -184,6 +201,13 @@ rb_bitarray_size(VALUE self)
184
201
  }
185
202
 
186
203
 
204
+ /* call-seq:
205
+ * bitarray.set_bit(index) -> bitarray
206
+ *
207
+ * Sets the bit at _index_ to 1. Negative indices count backwards from the end
208
+ * of _bitarray_. If _index_ is greater than the capacity of _bitarray_, an
209
+ * +IndexError+ is raised.
210
+ */
187
211
  static VALUE
188
212
  rb_bitarray_set_bit(VALUE self, VALUE bit)
189
213
  {
@@ -200,6 +224,11 @@ rb_bitarray_set_bit(VALUE self, VALUE bit)
200
224
  }
201
225
 
202
226
 
227
+ /* call-seq:
228
+ * bitarray.set_all_bits -> bitarray
229
+ *
230
+ * Sets all bits to 1.
231
+ */
203
232
  static VALUE
204
233
  rb_bitarray_set_all_bits(VALUE self)
205
234
  {
@@ -214,6 +243,13 @@ rb_bitarray_set_all_bits(VALUE self)
214
243
  }
215
244
 
216
245
 
246
+ /* call-seq:
247
+ * bitarray.clear_bit(index) -> bitarray
248
+ *
249
+ * Sets the bit at _index_ to 0. Negative indices count backwards from the end
250
+ * of _bitarray_. If _index_ is greater than the capacity of _bitarray_, an
251
+ * +IndexError+ is raised.
252
+ */
217
253
  static VALUE
218
254
  rb_bitarray_clear_bit(VALUE self, VALUE bit)
219
255
  {
@@ -230,6 +266,11 @@ rb_bitarray_clear_bit(VALUE self, VALUE bit)
230
266
  }
231
267
 
232
268
 
269
+ /* call-seq:
270
+ * bitarray.clear_all_bits -> bitarray
271
+ *
272
+ * Sets all bits to 0.
273
+ */
233
274
  static VALUE
234
275
  rb_bitarray_clear_all_bits(VALUE self)
235
276
  {
@@ -244,6 +285,13 @@ rb_bitarray_clear_all_bits(VALUE self)
244
285
  }
245
286
 
246
287
 
288
+ /* call-seq:
289
+ * bitarray[index] -> value
290
+ *
291
+ * Bit Reference---Returns the bit at _index_. Negative indices count backwards
292
+ * from the end of _bitarray_. If _index_ is greater than the capacity of
293
+ * _bitarray_, an +IndexError+ is raised.
294
+ */
247
295
  static VALUE
248
296
  rb_bitarray_get_bit(VALUE self, VALUE bit)
249
297
  {
@@ -262,6 +310,16 @@ rb_bitarray_get_bit(VALUE self, VALUE bit)
262
310
  }
263
311
 
264
312
 
313
+ /* call-seq:
314
+ * bitarray[index] = value -> value
315
+ *
316
+ * Bit Assignment---Sets the bit at _index_. _value_ must be 0 or 1. Negative
317
+ * indices are allowed, and will count backwards from the end of _bitarray_.
318
+ *
319
+ * If _index_ is greater than the capacity of _bitarray_, an +IndexError+ is
320
+ * raised. If _value_ is something other than 0 or 1, a +RuntimeError+ is
321
+ * raised.
322
+ */
265
323
  static VALUE
266
324
  rb_bitarray_assign_bit(VALUE self, VALUE bit, VALUE value)
267
325
  {
@@ -273,7 +331,7 @@ rb_bitarray_assign_bit(VALUE self, VALUE bit, VALUE value)
273
331
 
274
332
  int result = assign_bit(ba, index, bit_value);
275
333
  if (result == 1) {
276
- return self;
334
+ return value;
277
335
  } else if (result == 0) {
278
336
  rb_raise(rb_eIndexError, "index %ld out of bit array", (long)index);
279
337
  } else {
@@ -282,6 +340,12 @@ rb_bitarray_assign_bit(VALUE self, VALUE bit, VALUE value)
282
340
  }
283
341
 
284
342
 
343
+ /* call-seq:
344
+ * bitarray.inspect -> string
345
+ * bitarray.to_s -> string
346
+ *
347
+ * Create a printable version of _bitarray_.
348
+ */
285
349
  static VALUE
286
350
  rb_bitarray_inspect(VALUE self)
287
351
  {
@@ -302,6 +366,19 @@ rb_bitarray_inspect(VALUE self)
302
366
  }
303
367
 
304
368
 
369
+ /* call-seq:
370
+ * bitarray.each {|bit| block } -> bitarray
371
+ *
372
+ * Calls +block+ once for each bit in _bitarray_, passing that bit as a
373
+ * parameter.
374
+ *
375
+ * ba = BitArray.new(10)
376
+ * ba.each {|bit| print bit, " " }
377
+ *
378
+ * produces:
379
+ *
380
+ * 0 0 0 0 0 0 0 0 0 0
381
+ */
305
382
  static VALUE
306
383
  rb_bitarray_each(VALUE self)
307
384
  {
@@ -319,6 +396,11 @@ rb_bitarray_each(VALUE self)
319
396
  }
320
397
 
321
398
 
399
+ /* Document-class: BitArray
400
+ *
401
+ * An array of bits. Usage is similar to the standard Array class, but the only
402
+ * allowed elements are 1 and 0. BitArrays are not resizable.
403
+ */
322
404
  void
323
405
  Init_bitarray()
324
406
  {
@@ -327,7 +409,12 @@ Init_bitarray()
327
409
 
328
410
  rb_define_method(rb_bitarray_class, "initialize",
329
411
  rb_bitarray_initialize, 1);
412
+
413
+ /* TODO: apparently, we need to define an #initialize_copy method instead
414
+ * of clone.
415
+ */
330
416
  rb_define_method(rb_bitarray_class, "clone", rb_bitarray_clone, 0);
417
+ rb_define_alias(rb_bitarray_class, "dup", "clone");
331
418
  rb_define_method(rb_bitarray_class, "size", rb_bitarray_size, 0);
332
419
  rb_define_alias(rb_bitarray_class, "length", "size");
333
420
  rb_define_method(rb_bitarray_class, "set_bit", rb_bitarray_set_bit, 1);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ingramj-bitarray
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James E. Ingram