Class: SClust::Util::SparseVector
- Inherits:
-
Hash
- Object
- Hash
- SClust::Util::SparseVector
- Defined in:
- lib/sclust/util/sparse_vector.rb
Overview
Use cases:
Direct Known Subclasses
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(default_value = nil) ⇒ SparseVector
constructor
A new instance of SparseVector.
- #store(key, value) ⇒ Object (also: #[]=)
Constructor Details
#initialize(default_value = nil) ⇒ SparseVector
Returns a new instance of SparseVector.
35 36 37 38 |
# File 'lib/sclust/util/sparse_vector.rb', line 35 def initialize(default_value=nil) super(default_value) @default_value = default_value end |
Instance Method Details
#[](key) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/sclust/util/sparse_vector.rb', line 49 def [](key) if has_key?(key) super(key) else @default_value end end |
#store(key, value) ⇒ Object Also known as: []=
40 41 42 43 44 45 46 47 |
# File 'lib/sclust/util/sparse_vector.rb', line 40 def store(key, value) if ( @default_value == value) delete(key) if ( member?(key) ) value else super(key, value) end end |