2 summary::two-dimensional array
4 categories::Collections>Ordered
7 Represents a two-dimensional array of data. The number of rows and columns is fixed.
9 note:: It is possible to implement a similar behaviour using an "array-of-arrays" - see the examples towards the bottom of this page for comparison.::
14 Create an array of the specified size.
22 Build an Array2D from the supplied array.
24 a = Array2D.fromArray(3,4, [9,8,7,6,5,4,3,2,1,2,3,4]);
31 private::printOn, storeOn
34 Get a value from the array.
41 Put a value into the array.
48 Iterate over the columns. Each column will be passed to strong::func:: in turn.
54 Iterate over the rows. Each row will be passed to strong::func:: in turn.
60 Retrieve a single column.
66 Retrieve a single row.
72 Return a flat array containing the elements.
77 returns:: link::Classes/Array::
82 // "a" is an array-of-arrays
83 a = { { 100.0.rand }.dup(100) }.dup(100);
84 // "b" is an equivalent Array2D, made using the "fromArray" class method
85 b = Array2D.fromArray(100,100, a.flat);
91 // Speed comparison 1: random access
92 bench { 100.do(a[100.rand][100.rand]) }
93 bench { 100.do(b[100.rand, 100.rand]) }
95 // Speed comparison 2: iteration
96 bench { 100.do(a.do { |row| row.do { |item| item * 2 } }) }
97 bench { 100.do(b.do { |item| item * 2 }) }