type_array 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +0 -1
- data/ext/type_array/type_array.c +234 -0
- data/ext/type_array/type_array.h +22 -0
- data/lib/type_array/version.rb +1 -1
- data/test/test_type_array.rb +73 -0
- metadata +88 -73
data/README.rdoc
CHANGED
@@ -131,7 +131,6 @@ Running tests
|
|
131
131
|
== Todo
|
132
132
|
|
133
133
|
* Support Marshal dump / load
|
134
|
-
* Low level API for math operations on array elements without creating any Ruby objects
|
135
134
|
* Support structs / records
|
136
135
|
* Handle edges where coercion to and from Bignum is more appropriate
|
137
136
|
|
data/ext/type_array/type_array.c
CHANGED
@@ -29,6 +29,14 @@ static ID rb_type_array_intern_aset;
|
|
29
29
|
*/
|
30
30
|
DefineTypeArraySetter(int8, (signed char)NUM2CHR(item));
|
31
31
|
|
32
|
+
/*
|
33
|
+
* :nodoc:
|
34
|
+
* Defines operator functions for int8s at given offsets, according to host endianness.
|
35
|
+
*
|
36
|
+
*/
|
37
|
+
DefineTypeArrayOperators(int8, signed char, TACHR2FIX(val));
|
38
|
+
DefineTypeArrayOperator(eql, ==, int8, signed char, (val == 0 ? Qfalse : Qtrue));
|
39
|
+
|
32
40
|
/*
|
33
41
|
* :nodoc:
|
34
42
|
* Coerces an int8 at a given offset to a Ruby object, according to host endianness.
|
@@ -50,6 +58,14 @@ DefineTypeArraySetter(uint8, (unsigned char)NUM2CHR(item));
|
|
50
58
|
*/
|
51
59
|
DefineTypeArrayGetter(uint8, unsigned char, TACHR2FIX(val));
|
52
60
|
|
61
|
+
/*
|
62
|
+
* :nodoc:
|
63
|
+
* Defines operator functions for uint8s at given offsets, according to host endianness.
|
64
|
+
*
|
65
|
+
*/
|
66
|
+
DefineTypeArrayOperators(uint8, unsigned char, TACHR2FIX(val));
|
67
|
+
DefineTypeArrayOperator(eql, ==, uint8, unsigned char, (val == 0 ? Qfalse : Qtrue));
|
68
|
+
|
53
69
|
/*
|
54
70
|
* :nodoc:
|
55
71
|
* Coerces a Ruby object to an int16 at a given offset, according to host endianness.
|
@@ -64,6 +80,14 @@ DefineTypeArraySetter(int16, (short)NUM2INT(item));
|
|
64
80
|
*/
|
65
81
|
DefineTypeArrayGetter(int16, short, INT2FIX(val));
|
66
82
|
|
83
|
+
/*
|
84
|
+
* :nodoc:
|
85
|
+
* Defines operator functions for int16s at given offsets, according to host endianness.
|
86
|
+
*
|
87
|
+
*/
|
88
|
+
DefineTypeArrayOperators(int16, short, INT2FIX(val));
|
89
|
+
DefineTypeArrayOperator(eql, ==, int16, short, (val == 0 ? Qfalse : Qtrue));
|
90
|
+
|
67
91
|
/*
|
68
92
|
* :nodoc:
|
69
93
|
* Coerces a Ruby object to an unsigned int16 at a given offset, according to host endianness.
|
@@ -78,6 +102,14 @@ DefineTypeArraySetter(uint16, (unsigned short)NUM2INT(item));
|
|
78
102
|
*/
|
79
103
|
DefineTypeArrayGetter(uint16, unsigned short, INT2FIX(val));
|
80
104
|
|
105
|
+
/*
|
106
|
+
* :nodoc:
|
107
|
+
* Defines operator functions for uint16s at given offsets, according to host endianness.
|
108
|
+
*
|
109
|
+
*/
|
110
|
+
DefineTypeArrayOperators(uint16, unsigned short, INT2FIX(val));
|
111
|
+
DefineTypeArrayOperator(eql, ==, uint16, unsigned short, (val == 0 ? Qfalse : Qtrue));
|
112
|
+
|
81
113
|
/*
|
82
114
|
* :nodoc:
|
83
115
|
* Coerces a Ruby object to an int32 at a given offset, according to host endianness.
|
@@ -92,6 +124,14 @@ DefineTypeArraySetter(int32, NUM2INT(item));
|
|
92
124
|
*/
|
93
125
|
DefineTypeArrayGetter(int32, int, INT2FIX(val));
|
94
126
|
|
127
|
+
/*
|
128
|
+
* :nodoc:
|
129
|
+
* Defines operator functions for int32s at given offsets, according to host endianness.
|
130
|
+
*
|
131
|
+
*/
|
132
|
+
DefineTypeArrayOperators(int32, int, INT2FIX(val));
|
133
|
+
DefineTypeArrayOperator(eql, ==, int32, int, (val == 0 ? Qfalse : Qtrue));
|
134
|
+
|
95
135
|
/*
|
96
136
|
* :nodoc:
|
97
137
|
* Coerces a Ruby object to an unsigned int32 at a given offset, according to host endianness.
|
@@ -106,6 +146,14 @@ DefineTypeArraySetter(uint32, NUM2UINT(item));
|
|
106
146
|
*/
|
107
147
|
DefineTypeArrayGetter(uint32, unsigned int, UINT2NUM(val));
|
108
148
|
|
149
|
+
/*
|
150
|
+
* :nodoc:
|
151
|
+
* Defines operator functions for uint32s at given offsets, according to host endianness.
|
152
|
+
*
|
153
|
+
*/
|
154
|
+
DefineTypeArrayOperators(uint32, unsigned int, UINT2NUM(val));
|
155
|
+
DefineTypeArrayOperator(eql, ==, uint32, unsigned int, (val == 0 ? Qfalse : Qtrue));
|
156
|
+
|
109
157
|
/*
|
110
158
|
* :nodoc:
|
111
159
|
* Coerces a Ruby object to a float32 (float) at a given offset, according to host endianness.
|
@@ -137,6 +185,14 @@ static void rb_type_array_aset_float32(rb_array_buffer_t *buf, long index, VALUE
|
|
137
185
|
*/
|
138
186
|
DefineTypeArrayGetter(float32, float, rb_float_new((double)val));
|
139
187
|
|
188
|
+
/*
|
189
|
+
* :nodoc:
|
190
|
+
* Defines operator functions for float32s at given offsets, according to host endianness.
|
191
|
+
*
|
192
|
+
*/
|
193
|
+
DefineTypeArrayOperators(float32, float, rb_float_new((double)val));
|
194
|
+
DefineTypeArrayOperator(eql, ==, float32, float, (val == 0 ? Qfalse : Qtrue));
|
195
|
+
|
140
196
|
/*
|
141
197
|
* :nodoc:
|
142
198
|
* Coerces a Ruby object to a float64 (double) at a given offset, according to host endianness.
|
@@ -168,6 +224,14 @@ static void rb_type_array_aset_float64(rb_array_buffer_t *buf, long index, VALUE
|
|
168
224
|
*/
|
169
225
|
DefineTypeArrayGetter(float64, double, rb_float_new(val));
|
170
226
|
|
227
|
+
/*
|
228
|
+
* :nodoc:
|
229
|
+
* Defines operator functions for float64s at given offsets, according to host endianness.
|
230
|
+
*
|
231
|
+
*/
|
232
|
+
DefineTypeArrayOperators(float64, double, rb_float_new(val));
|
233
|
+
DefineTypeArrayOperator(eql, ==, float64, double, (val == 0 ? Qfalse : Qtrue));
|
234
|
+
|
171
235
|
/*
|
172
236
|
* :nodoc:
|
173
237
|
* Asserts type alignment.
|
@@ -291,27 +355,67 @@ static VALUE rb_type_array_s_new(int argc, VALUE *argv, VALUE klass)
|
|
291
355
|
if (klass == rb_cInt8Array) {
|
292
356
|
array->aref_fn = rb_type_array_aref_int8;
|
293
357
|
array->aset_fn = rb_type_array_aset_int8;
|
358
|
+
array->mul_fn = rb_type_array_mul_int8;
|
359
|
+
array->plus_fn = rb_type_array_plus_int8;
|
360
|
+
array->minus_fn = rb_type_array_minus_int8;
|
361
|
+
array->div_fn = rb_type_array_div_int8;
|
362
|
+
array->eql_fn = rb_type_array_eql_int8;
|
294
363
|
} else if (klass == rb_cUInt8Array) {
|
295
364
|
array->aref_fn = rb_type_array_aref_uint8;
|
296
365
|
array->aset_fn = rb_type_array_aset_uint8;
|
366
|
+
array->mul_fn = rb_type_array_mul_uint8;
|
367
|
+
array->plus_fn = rb_type_array_plus_uint8;
|
368
|
+
array->minus_fn = rb_type_array_minus_uint8;
|
369
|
+
array->div_fn = rb_type_array_div_uint8;
|
370
|
+
array->eql_fn = rb_type_array_eql_uint8;
|
297
371
|
} else if (klass == rb_cInt16Array) {
|
298
372
|
array->aref_fn = rb_type_array_aref_int16;
|
299
373
|
array->aset_fn = rb_type_array_aset_int16;
|
374
|
+
array->mul_fn = rb_type_array_mul_int16;
|
375
|
+
array->plus_fn = rb_type_array_plus_int16;
|
376
|
+
array->minus_fn = rb_type_array_minus_int16;
|
377
|
+
array->div_fn = rb_type_array_div_int16;
|
378
|
+
array->eql_fn = rb_type_array_eql_int16;
|
300
379
|
} else if (klass == rb_cUInt16Array) {
|
301
380
|
array->aref_fn = rb_type_array_aref_uint16;
|
302
381
|
array->aset_fn = rb_type_array_aset_uint16;
|
382
|
+
array->mul_fn = rb_type_array_mul_uint16;
|
383
|
+
array->plus_fn = rb_type_array_plus_uint16;
|
384
|
+
array->minus_fn = rb_type_array_minus_uint16;
|
385
|
+
array->div_fn = rb_type_array_div_uint16;
|
386
|
+
array->eql_fn = rb_type_array_eql_uint16;
|
303
387
|
} else if (klass == rb_cInt32Array) {
|
304
388
|
array->aref_fn = rb_type_array_aref_int32;
|
305
389
|
array->aset_fn = rb_type_array_aset_int32;
|
390
|
+
array->mul_fn = rb_type_array_mul_int32;
|
391
|
+
array->plus_fn = rb_type_array_plus_int32;
|
392
|
+
array->minus_fn = rb_type_array_minus_int32;
|
393
|
+
array->div_fn = rb_type_array_div_int32;
|
394
|
+
array->eql_fn = rb_type_array_eql_int32;
|
306
395
|
} else if (klass == rb_cUInt32Array) {
|
307
396
|
array->aref_fn = rb_type_array_aref_uint32;
|
308
397
|
array->aset_fn = rb_type_array_aset_uint32;
|
398
|
+
array->mul_fn = rb_type_array_mul_uint32;
|
399
|
+
array->plus_fn = rb_type_array_plus_uint32;
|
400
|
+
array->minus_fn = rb_type_array_minus_uint32;
|
401
|
+
array->div_fn = rb_type_array_div_uint32;
|
402
|
+
array->eql_fn = rb_type_array_eql_uint32;
|
309
403
|
} else if (klass == rb_cFloat32Array) {
|
310
404
|
array->aref_fn = rb_type_array_aref_float32;
|
311
405
|
array->aset_fn = rb_type_array_aset_float32;
|
406
|
+
array->mul_fn = rb_type_array_mul_float32;
|
407
|
+
array->plus_fn = rb_type_array_plus_float32;
|
408
|
+
array->minus_fn = rb_type_array_minus_float32;
|
409
|
+
array->div_fn = rb_type_array_div_float32;
|
410
|
+
array->eql_fn = rb_type_array_eql_float32;
|
312
411
|
} else if (klass == rb_cFloat64Array) {
|
313
412
|
array->aref_fn = rb_type_array_aref_float64;
|
314
413
|
array->aset_fn = rb_type_array_aset_float64;
|
414
|
+
array->mul_fn = rb_type_array_mul_float64;
|
415
|
+
array->plus_fn = rb_type_array_plus_float64;
|
416
|
+
array->minus_fn = rb_type_array_minus_float64;
|
417
|
+
array->div_fn = rb_type_array_div_float64;
|
418
|
+
array->eql_fn = rb_type_array_eql_float64;
|
315
419
|
}
|
316
420
|
|
317
421
|
if (FIXNUM_P(obj)) {
|
@@ -382,6 +486,131 @@ static VALUE rb_type_array_byte_length(VALUE obj)
|
|
382
486
|
return ULONG2NUM(ary->byte_length);
|
383
487
|
}
|
384
488
|
|
489
|
+
/*
|
490
|
+
* call-seq:
|
491
|
+
* ary.mul(0,1) => Fixnum, Bignum or Float
|
492
|
+
*
|
493
|
+
* Gets two values at given offsets and multiples them - only the result's coerced to a Ruby object.
|
494
|
+
*
|
495
|
+
* === Examples
|
496
|
+
* buf = ArrayBuffer.new(16) => ArrayBuffer
|
497
|
+
* ary = Int32Array.new(buf) => Int32Array
|
498
|
+
* ary[0] = 2 => nil
|
499
|
+
* ary[1] = 4 => nil
|
500
|
+
* ary[2] = 8 => nil
|
501
|
+
*
|
502
|
+
* ary.mul(0,1) => 8
|
503
|
+
* ary.mul(1,2) => 32
|
504
|
+
*/
|
505
|
+
static VALUE rb_type_array_mul(VALUE obj, VALUE off1, VALUE off2)
|
506
|
+
{
|
507
|
+
GetTypeArray(obj);
|
508
|
+
GetArrayBuffer(ary->buf);
|
509
|
+
long offset1 = rb_type_array_assert_offset(ary, off1);
|
510
|
+
long offset2 = rb_type_array_assert_offset(ary, off2);
|
511
|
+
return ary->mul_fn(buf->buf, offset1, offset2);
|
512
|
+
}
|
513
|
+
|
514
|
+
/*
|
515
|
+
* call-seq:
|
516
|
+
* ary.plus(0,1) => Fixnum, Bignum or Float
|
517
|
+
*
|
518
|
+
* Gets two values at given offsets and adds them - only the result's coerced to a Ruby object.
|
519
|
+
*
|
520
|
+
* === Examples
|
521
|
+
* buf = ArrayBuffer.new(16) => ArrayBuffer
|
522
|
+
* ary = Int32Array.new(buf) => Int32Array
|
523
|
+
* ary[0] = 2 => nil
|
524
|
+
* ary[1] = 4 => nil
|
525
|
+
* ary[2] = 8 => nil
|
526
|
+
*
|
527
|
+
* ary.plus(0,1) => 6
|
528
|
+
* ary.plus(1,2) => 12
|
529
|
+
*/
|
530
|
+
static VALUE rb_type_array_plus(VALUE obj, VALUE off1, VALUE off2)
|
531
|
+
{
|
532
|
+
GetTypeArray(obj);
|
533
|
+
GetArrayBuffer(ary->buf);
|
534
|
+
long offset1 = rb_type_array_assert_offset(ary, off1);
|
535
|
+
long offset2 = rb_type_array_assert_offset(ary, off2);
|
536
|
+
return ary->plus_fn(buf->buf, offset1, offset2);
|
537
|
+
}
|
538
|
+
|
539
|
+
/*
|
540
|
+
* call-seq:
|
541
|
+
* ary.minus(0,1) => Fixnum, Bignum or Float
|
542
|
+
*
|
543
|
+
* Gets two values at given offsets and subtracts them - only the result's coerced to a Ruby object.
|
544
|
+
*
|
545
|
+
* === Examples
|
546
|
+
* buf = ArrayBuffer.new(16) => ArrayBuffer
|
547
|
+
* ary = Int32Array.new(buf) => Int32Array
|
548
|
+
* ary[0] = 2 => nil
|
549
|
+
* ary[1] = 4 => nil
|
550
|
+
* ary[2] = 8 => nil
|
551
|
+
*
|
552
|
+
* ary.minus(1, 0) => 2
|
553
|
+
* ary.minus(2, 1) => 4
|
554
|
+
*/
|
555
|
+
static VALUE rb_type_array_minus(VALUE obj, VALUE off1, VALUE off2)
|
556
|
+
{
|
557
|
+
GetTypeArray(obj);
|
558
|
+
GetArrayBuffer(ary->buf);
|
559
|
+
long offset1 = rb_type_array_assert_offset(ary, off1);
|
560
|
+
long offset2 = rb_type_array_assert_offset(ary, off2);
|
561
|
+
return ary->minus_fn(buf->buf, offset1, offset2);
|
562
|
+
}
|
563
|
+
|
564
|
+
/*
|
565
|
+
* call-seq:
|
566
|
+
* ary.div(0,1) => Fixnum, Bignum or Float
|
567
|
+
*
|
568
|
+
* Gets two values at given offsets and divides them - only the result's coerced to a Ruby object.
|
569
|
+
*
|
570
|
+
* === Examples
|
571
|
+
* buf = ArrayBuffer.new(16) => ArrayBuffer
|
572
|
+
* ary = Int32Array.new(buf) => Int32Array
|
573
|
+
* ary[0] = 2 => nil
|
574
|
+
* ary[1] = 4 => nil
|
575
|
+
* ary[2] = 8 => nil
|
576
|
+
*
|
577
|
+
* ary.div(1, 0) => 2
|
578
|
+
* ary.div(2, 1) => 2
|
579
|
+
*/
|
580
|
+
static VALUE rb_type_array_div(VALUE obj, VALUE off1, VALUE off2)
|
581
|
+
{
|
582
|
+
GetTypeArray(obj);
|
583
|
+
GetArrayBuffer(ary->buf);
|
584
|
+
long offset1 = rb_type_array_assert_offset(ary, off1);
|
585
|
+
long offset2 = rb_type_array_assert_offset(ary, off2);
|
586
|
+
return ary->div_fn(buf->buf, offset1, offset2);
|
587
|
+
}
|
588
|
+
|
589
|
+
/*
|
590
|
+
* call-seq:
|
591
|
+
* ary.div(0,1) => Fixnum, Bignum or Float
|
592
|
+
*
|
593
|
+
* Gets two values at given offsets and divides them - only the result's coerced to a Ruby object.
|
594
|
+
*
|
595
|
+
* === Examples
|
596
|
+
* buf = ArrayBuffer.new(16) => ArrayBuffer
|
597
|
+
* ary = Int32Array.new(buf) => Int32Array
|
598
|
+
* ary[0] = 2 => nil
|
599
|
+
* ary[1] = 4 => nil
|
600
|
+
* ary[2] = 8 => nil
|
601
|
+
*
|
602
|
+
* ary.div(1, 0) => 2
|
603
|
+
* ary.div(2, 1) => 2
|
604
|
+
*/
|
605
|
+
static VALUE rb_type_array_eql(VALUE obj, VALUE off1, VALUE off2)
|
606
|
+
{
|
607
|
+
GetTypeArray(obj);
|
608
|
+
GetArrayBuffer(ary->buf);
|
609
|
+
long offset1 = rb_type_array_assert_offset(ary, off1);
|
610
|
+
long offset2 = rb_type_array_assert_offset(ary, off2);
|
611
|
+
return ary->eql_fn(buf->buf, offset1, offset2);
|
612
|
+
}
|
613
|
+
|
385
614
|
/*
|
386
615
|
* call-seq:
|
387
616
|
* ary.length => Fixnum
|
@@ -537,4 +766,9 @@ void _init_type_array()
|
|
537
766
|
rb_define_method(rb_cTypeArray, "to_s", rb_type_array_to_s, 0);
|
538
767
|
rb_define_method(rb_cTypeArray, "[]=", rb_type_array_aset, 2);
|
539
768
|
rb_define_method(rb_cTypeArray, "[]", rb_type_array_aget, 1);
|
769
|
+
rb_define_method(rb_cTypeArray, "mul", rb_type_array_mul, 2);
|
770
|
+
rb_define_method(rb_cTypeArray, "plus", rb_type_array_plus, 2);
|
771
|
+
rb_define_method(rb_cTypeArray, "minus", rb_type_array_minus, 2);
|
772
|
+
rb_define_method(rb_cTypeArray, "div", rb_type_array_div, 2);
|
773
|
+
rb_define_method(rb_cTypeArray, "eql", rb_type_array_eql, 2);
|
540
774
|
}
|
data/ext/type_array/type_array.h
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
|
4
4
|
typedef void (type_array_aset_fn) (rb_array_buffer_t *buf, long index, VALUE item);
|
5
5
|
typedef VALUE (type_array_aref_fn) (rb_array_buffer_t *buf, long index);
|
6
|
+
typedef VALUE (type_array_operator_fn) (rb_array_buffer_t *buf, long off1, long off2);
|
6
7
|
|
7
8
|
typedef struct {
|
8
9
|
unsigned long size;
|
@@ -11,6 +12,11 @@ typedef struct {
|
|
11
12
|
unsigned long byte_offset;
|
12
13
|
type_array_aset_fn *aset_fn;
|
13
14
|
type_array_aref_fn *aref_fn;
|
15
|
+
type_array_operator_fn *mul_fn;
|
16
|
+
type_array_operator_fn *plus_fn;
|
17
|
+
type_array_operator_fn *minus_fn;
|
18
|
+
type_array_operator_fn *div_fn;
|
19
|
+
type_array_operator_fn *eql_fn;
|
14
20
|
VALUE buf;
|
15
21
|
} rb_type_array_t;
|
16
22
|
|
@@ -35,4 +41,20 @@ void _init_type_array();
|
|
35
41
|
return coercion; \
|
36
42
|
}
|
37
43
|
|
44
|
+
#define DefineTypeArrayOperators(name, type, coercion) \
|
45
|
+
DefineTypeArrayOperator(mul, *, name, type, coercion); \
|
46
|
+
DefineTypeArrayOperator(plus, +, name, type, coercion); \
|
47
|
+
DefineTypeArrayOperator(minus, -, name, type, coercion); \
|
48
|
+
DefineTypeArrayOperator(div, /, name, type, coercion); \
|
49
|
+
|
50
|
+
#define DefineTypeArrayOperator(op_name, op, name, type, coercion) \
|
51
|
+
VALUE rb_type_array_##op_name##_##name(rb_array_buffer_t *buf, long off1, long off2) \
|
52
|
+
{ \
|
53
|
+
type val; \
|
54
|
+
type val1 = rb_type_array_get_##name(buf, off1, TYPE_ARRAY_IS_LITTLE_ENDIAN); \
|
55
|
+
type val2 = rb_type_array_get_##name(buf, off2, TYPE_ARRAY_IS_LITTLE_ENDIAN); \
|
56
|
+
val = val1 op val2; \
|
57
|
+
return coercion; \
|
58
|
+
}
|
59
|
+
|
38
60
|
#endif
|
data/lib/type_array/version.rb
CHANGED
data/test/test_type_array.rb
CHANGED
@@ -152,4 +152,77 @@ class TestTypeArray < TypeArrayTestCase
|
|
152
152
|
ensure
|
153
153
|
s.close rescue nil
|
154
154
|
end
|
155
|
+
|
156
|
+
def test_mul
|
157
|
+
buf = ArrayBuffer.new(16)
|
158
|
+
|
159
|
+
ary = Int32Array.new(buf)
|
160
|
+
ary[0] = 2
|
161
|
+
ary[1] = 4
|
162
|
+
ary[2] = 8
|
163
|
+
|
164
|
+
assert_equal 8, ary.mul(0,1)
|
165
|
+
assert_equal 32, ary.mul(1, 2)
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_plus
|
169
|
+
buf = ArrayBuffer.new(16)
|
170
|
+
|
171
|
+
ary = Int32Array.new(buf)
|
172
|
+
ary[0] = 2
|
173
|
+
ary[1] = 4
|
174
|
+
ary[2] = 8
|
175
|
+
|
176
|
+
assert_equal 6, ary.plus(0,1)
|
177
|
+
assert_equal 12, ary.plus(1, 2)
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_minus
|
181
|
+
buf = ArrayBuffer.new(16)
|
182
|
+
|
183
|
+
ary = Int32Array.new(buf)
|
184
|
+
ary[0] = 2
|
185
|
+
ary[1] = 4
|
186
|
+
ary[2] = 8
|
187
|
+
|
188
|
+
assert_equal 2, ary.minus(1,0)
|
189
|
+
assert_equal 4, ary.minus(2, 1)
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_div
|
193
|
+
buf = ArrayBuffer.new(16)
|
194
|
+
|
195
|
+
ary = Int32Array.new(buf)
|
196
|
+
ary[0] = 2
|
197
|
+
ary[1] = 4
|
198
|
+
ary[2] = 8
|
199
|
+
|
200
|
+
assert_equal 2, ary.div(1,0)
|
201
|
+
assert_equal 2, ary.div(2, 1)
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_eql
|
205
|
+
buf = ArrayBuffer.new(16)
|
206
|
+
|
207
|
+
ary = Int32Array.new(buf)
|
208
|
+
ary[0] = 2
|
209
|
+
ary[1] = 4
|
210
|
+
ary[2] = 4
|
211
|
+
ary[3] = 2
|
212
|
+
|
213
|
+
assert ary.eql(0, 3)
|
214
|
+
assert ary.eql(1, 2)
|
215
|
+
assert !ary.eql(0, 1)
|
216
|
+
|
217
|
+
buf = ArrayBuffer.new(24)
|
218
|
+
|
219
|
+
ary = Float64Array.new(buf)
|
220
|
+
|
221
|
+
ary[0] = 2.33
|
222
|
+
ary[1] = 2.33
|
223
|
+
ary[2] = 7.45
|
224
|
+
|
225
|
+
assert ary.eql(0,1)
|
226
|
+
assert !ary.eql(1,2)
|
227
|
+
end
|
155
228
|
end
|
metadata
CHANGED
@@ -1,112 +1,127 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: type_array
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
4
5
|
prerelease:
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: "0.2"
|
6
10
|
platform: ruby
|
7
11
|
authors:
|
8
|
-
|
12
|
+
- "Lourens Naud\xC3\xA9"
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
16
|
|
13
17
|
date: 2012-07-12 00:00:00 Z
|
14
18
|
dependencies:
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
- !ruby/object:Gem::Dependency
|
20
|
+
name: rake-compiler
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 63
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 8
|
31
|
+
- 0
|
32
|
+
version: 0.8.0
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
26
35
|
description: TypeArray - Ruby implementation of the ECMAScript spec ( http://wiki.ecmascript.org/doku.php?id=strawman:typed_arrays )
|
27
36
|
email:
|
28
|
-
|
37
|
+
- lourens@methodmissing.com
|
29
38
|
executables: []
|
30
39
|
|
31
40
|
extensions:
|
32
|
-
|
41
|
+
- ext/type_array/extconf.rb
|
33
42
|
extra_rdoc_files: []
|
34
43
|
|
35
44
|
files:
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
45
|
+
- .gitignore
|
46
|
+
- .travis.yml
|
47
|
+
- CHANGELOG.rdoc
|
48
|
+
- Gemfile
|
49
|
+
- Gemfile.lock
|
50
|
+
- README.rdoc
|
51
|
+
- Rakefile
|
52
|
+
- ext/type_array/array_buffer.c
|
53
|
+
- ext/type_array/array_buffer.h
|
54
|
+
- ext/type_array/data_view.c
|
55
|
+
- ext/type_array/data_view.h
|
56
|
+
- ext/type_array/extconf.rb
|
57
|
+
- ext/type_array/jruby.h
|
58
|
+
- ext/type_array/prelude.h
|
59
|
+
- ext/type_array/rubinius.h
|
60
|
+
- ext/type_array/ruby18.h
|
61
|
+
- ext/type_array/ruby19.h
|
62
|
+
- ext/type_array/type_array.c
|
63
|
+
- ext/type_array/type_array.h
|
64
|
+
- ext/type_array/type_array_ext.c
|
65
|
+
- ext/type_array/type_array_ext.h
|
66
|
+
- lib/type_array.rb
|
67
|
+
- lib/type_array/io.rb
|
68
|
+
- lib/type_array/version.rb
|
69
|
+
- test/helper.rb
|
70
|
+
- test/test_array_buffer.rb
|
71
|
+
- test/test_data_view.rb
|
72
|
+
- test/test_float_32_array.rb
|
73
|
+
- test/test_float_64_array.rb
|
74
|
+
- test/test_int_16_array.rb
|
75
|
+
- test/test_int_32_array.rb
|
76
|
+
- test/test_int_8_array.rb
|
77
|
+
- test/test_type_array.rb
|
78
|
+
- test/test_uint_16_array.rb
|
79
|
+
- test/test_uint_32_array.rb
|
80
|
+
- test/test_uint_8_array.rb
|
81
|
+
- type_array.gemspec
|
73
82
|
homepage: http://github.com/methodmissing/type_array
|
74
83
|
licenses: []
|
75
84
|
|
76
85
|
post_install_message:
|
77
86
|
rdoc_options:
|
78
|
-
|
87
|
+
- --charset=UTF-8
|
79
88
|
require_paths:
|
80
|
-
|
89
|
+
- lib
|
81
90
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
91
|
none: false
|
83
92
|
requirements:
|
84
|
-
|
85
|
-
|
86
|
-
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
version: "0"
|
87
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
100
|
none: false
|
89
101
|
requirements:
|
90
|
-
|
91
|
-
|
92
|
-
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
93
108
|
requirements: []
|
94
109
|
|
95
110
|
rubyforge_project:
|
96
|
-
rubygems_version: 1.8.
|
111
|
+
rubygems_version: 1.8.15
|
97
112
|
signing_key:
|
98
113
|
specification_version: 3
|
99
114
|
summary: Typed Arrays for Ruby
|
100
115
|
test_files:
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
116
|
+
- test/helper.rb
|
117
|
+
- test/test_array_buffer.rb
|
118
|
+
- test/test_data_view.rb
|
119
|
+
- test/test_float_32_array.rb
|
120
|
+
- test/test_float_64_array.rb
|
121
|
+
- test/test_int_16_array.rb
|
122
|
+
- test/test_int_32_array.rb
|
123
|
+
- test/test_int_8_array.rb
|
124
|
+
- test/test_type_array.rb
|
125
|
+
- test/test_uint_16_array.rb
|
126
|
+
- test/test_uint_32_array.rb
|
127
|
+
- test/test_uint_8_array.rb
|