Class: SClust::Util::SparseLabeledVector
- Inherits:
-
SparseVector
- Object
- Hash
- SparseVector
- SClust::Util::SparseLabeledVector
- Defined in:
- lib/sclust/util/sparse_vector.rb
Instance Attribute Summary collapse
-
#key_map ⇒ Object
readonly
Map keys to the user-defined label.
-
#label_map ⇒ Object
readonly
Map labels to the key the data is stored under.
Instance Method Summary collapse
- #delete(key) ⇒ Object
-
#initialize(default_value = nil) ⇒ SparseLabeledVector
constructor
A new instance of SparseLabeledVector.
-
#store(key, value, label = nil) ⇒ Object
Aliased to []=, this stored the (key, value) pair as in the Hash class but accepts an optional 3rd element which will label the key.
Methods inherited from SparseVector
Constructor Details
#initialize(default_value = nil) ⇒ SparseLabeledVector
Returns a new instance of SparseLabeledVector.
69 70 71 72 73 |
# File 'lib/sclust/util/sparse_vector.rb', line 69 def initialize(default_value=nil) super(default_value) @label_map = {} @key_map = {} end |
Instance Attribute Details
#key_map ⇒ Object (readonly)
Map keys to the user-defined label.
64 65 66 |
# File 'lib/sclust/util/sparse_vector.rb', line 64 def key_map @key_map end |
#label_map ⇒ Object (readonly)
Map labels to the key the data is stored under.
67 68 69 |
# File 'lib/sclust/util/sparse_vector.rb', line 67 def label_map @label_map end |
Instance Method Details
#delete(key) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/sclust/util/sparse_vector.rb', line 86 def delete(key) if super(key) label = @key_map.delete(key) @label_map.delete(label) if label end end |
#store(key, value, label = nil) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/sclust/util/sparse_vector.rb', line 77 def store(key, value, label=nil) super(key, value) if label @label_map[label] = key @key_map[key] = label end end |