Class: SClust::Util::SparseVector

Inherits:
Hash
  • Object
show all
Defined in:
lib/sclust/util/sparse_vector.rb

Overview

Use cases:

Direct Known Subclasses

SparseLabeledVector

Instance Method Summary collapse

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