Class: DS::TriMatrix
- Inherits:
-
Object
- Object
- DS::TriMatrix
- Defined in:
- lib/ds/matrixes/tri_matrix.rb
Instance Method Summary collapse
-
#[](x, y) ⇒ Object
Returns element at index x,y (or y,x).
-
#[]=(x, y, v) ⇒ Object
Sets the element at index x,y (or y,x).
-
#initialize(init = 0) ⇒ TriMatrix
constructor
Creates new triangular matrix.
- #to_a ⇒ Object
Constructor Details
#initialize(init = 0) ⇒ TriMatrix
Creates new triangular matrix.
7 8 9 |
# File 'lib/ds/matrixes/tri_matrix.rb', line 7 def initialize(init=0) @store =ExpandableArray.new(0,init) end |
Instance Method Details
#[](x, y) ⇒ Object
Returns element at index x,y (or y,x).
12 13 14 15 16 |
# File 'lib/ds/matrixes/tri_matrix.rb', line 12 def [](x,y) x,y = y,x if y > x index = (x*x+x)/2 +y @store[index] end |
#[]=(x, y, v) ⇒ Object
Sets the element at index x,y (or y,x).
19 20 21 22 23 |
# File 'lib/ds/matrixes/tri_matrix.rb', line 19 def []=(x,y,v) x,y = y,x if y>x index = (x*x+x)/2 +y @store[index] = v end |
#to_a ⇒ Object
25 26 27 |
# File 'lib/ds/matrixes/tri_matrix.rb', line 25 def to_a @store end |