Class: Coopy::SparseSheet
- Inherits:
-
Object
- Object
- Coopy::SparseSheet
- Defined in:
- lib/lib/coopy/sparse_sheet.rb
Instance Method Summary collapse
- #get(x, y) ⇒ Object
-
#initialize ⇒ SparseSheet
constructor
A new instance of SparseSheet.
- #non_destructive_resize(w, h, zero) ⇒ Object
- #resize(w, h, zero) ⇒ Object
- #set(x, y, val) ⇒ Object
Constructor Details
#initialize ⇒ SparseSheet
Returns a new instance of SparseSheet.
7 8 9 |
# File 'lib/lib/coopy/sparse_sheet.rb', line 7 def initialize @h = @w = 0 end |
Instance Method Details
#get(x, y) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/lib/coopy/sparse_sheet.rb', line 31 def get(x,y) cursor = @row[y] return @zero if cursor == nil val = cursor[x] return @zero if val == nil val end |
#non_destructive_resize(w, h, zero) ⇒ Object
25 26 27 28 29 |
# File 'lib/lib/coopy/sparse_sheet.rb', line 25 def non_destructive_resize(w,h,zero) @w = w @h = h @zero = zero end |
#resize(w, h, zero) ⇒ Object
20 21 22 23 |
# File 'lib/lib/coopy/sparse_sheet.rb', line 20 def resize(w,h,zero) @row = {} self.non_destructive_resize(w,h,zero) end |
#set(x, y, val) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/lib/coopy/sparse_sheet.rb', line 39 def set(x,y,val) cursor = @row[y] if cursor == nil cursor = {} @row[y] = cursor end cursor[x] = val end |