Class: LogicTools::HashCounter

Inherits:
Hash
  • Object
show all
Defined in:
lib/logic_tools/minimal_column_covers.rb

Overview

Class for storing and counting occurences of objects.

Instance Method Summary collapse

Constructor Details

#initializeHashCounter

Creates a new hash counter.



53
54
55
# File 'lib/logic_tools/minimal_column_covers.rb', line 53

def initialize
    self.default = 0
end

Instance Method Details

#dec(element) ⇒ Object

Decrements the number of element.



63
64
65
66
67
68
# File 'lib/logic_tools/minimal_column_covers.rb', line 63

def dec(element)
    if (self[elem] -= 1) == 0 then
        # No more instance of the element, remove the entry.
        self.delete(elem)
    end
end

#inc(element) ⇒ Object

Increments the number of element.



58
59
60
# File 'lib/logic_tools/minimal_column_covers.rb', line 58

def inc(element)
    self[elem] += 1
end